求助:HELLO WORLD用C時的怪狀況
先貼一段代碼#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)象
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
又測了一把,發(fā)現(xiàn)只要是輸入12個字符長度的時候,這個‘y’就會出現(xiàn)。請高手相告
posted on 2011-01-17 00:00 志華 閱讀(1780) 評論(7) 編輯 收藏 引用 所屬分類: Ubuntu