一个简单的strcmp函数有关问题,新手分不多,希望各位大侠见谅
一个简单的strcmp函数问题,新手分不多,希望各位大侠见谅
char line[1024];
cahr point[1024];
char empty= " ";
char *abc= "abc "
strcpy(line,empty);
strcpy(point,abc);
printf( "line=%s\n ",line);
printf( "point=%s\n ",point);
printf( "strcmp(line,empty)=%d\n ",strcmp(line,empty));
printf( "strcmp(line,\ "\ ")=%d\n ",strcmp(line, " ")); \ =0(相等)
printf( "strcmp(point,\ "abc\ ")=%d\n ",strcmp(point, "abc "));\=1
printf( "strcmp(line,\ "abc\ ")=%d\n ",strcmp(point,abc));\=0
********************
打印的结果如下:
line=
point=abc
strcmp(line,empty)=0
strcmp(line, " ")=0
strcmp(point, "abc ")=1
strcmp(point,abc)=0
********************
我有点不明白这个 "abc "和变量abc字符串不是一样的吗?为什么用strcmp比较会出现不同的结果,还有用line与empty和 " "分别比较又是相同的。真迷糊了,C语言中处理字符串是个麻烦的事情啊:)