先贴一段代码
#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;
}
再贴奇怪的现象
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'是怎么出现的呢?
又测了一把,发现只要是输入12个字符长度的时候,这个‘y’就会出现。请高手相告