字符串比较必须使用strcmp

char s1[]="this"
char *s2 = "this"
if(s1=="this"){
printf("s1 is equal to 'this' \n");
}
if(s2=="this"){
printf("s2 is equal to 'this'\n");
}

注意,不会输出"s1 is equal to 'this' \n",会输出"s2 is equal to 'this'\n",因为s=="this"比较的实际上是内存地址。
所以如果比较字符串是否相同,还是应该使用strcmp(x1,x2)。返回值等于x1-x2;

上一篇:细说ES7 JavaScript Decorators


下一篇:android开发学习笔记系列(4)--android动态布局