首页 > 其他 > 详细

字符串比较必须使用strcmp

时间:2015-12-05 14:19:23      阅读:146      评论:0      收藏:0      [点我收藏+]
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;

字符串比较必须使用strcmp

原文:http://www.cnblogs.com/jxzheng/p/5021443.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!