首页 > 编程语言 > 详细

[C]记录C语言中由于粗心遇到的奇葩错误.

时间:2016-07-12 11:56:54      阅读:228      评论:0      收藏:0      [点我收藏+]

1.

正确代码:

        for( word = strtok( buf, whitespace); word != NULL; word = strtok( NULL, whitespace)) {
            if (strcmp(word,"the" )  == 0  )

错误代码:

        for( word = strtok( buf, whitespace); word != NULL; word = strtok( NULL, whitespace));{
            if (strcmp(word,"the" )  == 0  )

错误原因: 由于多了个分号.所以for循环体中实际执行的代码是 ; 这行空语句, if语句则变成了循环体外,

所以在调用strcmp中,参数word将永远为NULL.

[C]记录C语言中由于粗心遇到的奇葩错误.

原文:http://www.cnblogs.com/NewZi/p/5662681.html

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