先貼一段代碼
#include <stdio.h>
#include <cs50.h>
#include <stdlib.h>
#include <string.h>
int
main(int argc, char *argv[]) {
printf("Input a string:");
char *text=GetString();
char *tmp=(char *)malloc(sizeof(char) * strlen(text));
memcpy(tmp,text,strlen(text));
printf("%s\n%s\n",text,tmp);
return 0;
}
再貼奇怪的現(xiàn)象
zhihua@ThinkPad (~/cs50/2009fall/psets/2): make test
gcc -ggdb -std=c99 -Wall -Werror -Wformat=0 test.c -lcs50 -lm -o test
zhihua@ThinkPad (~/cs50/2009fall/psets/2): ./test
Input a string:HELLO WORLD
HELLO WORLD
HELLO WORLD
zhihua@ThinkPad (~/cs50/2009fall/psets/2): ./test
Input a string:HELLO,WORLD
HELLO,WORLD
HELLO,WORLD
zhihua@ThinkPad (~/cs50/2009fall/psets/2): ./test
Input a string:HELLO, WORLD
HELLO, WORLD
HELLO, WORLDy
很奇怪這個‘y'是怎么出現(xiàn)的呢?
又測了一把,發(fā)現(xiàn)只要是輸入12個字符長度的時候,這個‘y’就會出現(xiàn)。請高手相告