![](https://iknow-base.cdn.bcebos.com/lxb/notice.png)
C语言strncmp返回值问题
#include<stdio.h>#include<string.h>intmain(){chars[200]="whatthehellisgoingon?";print...
#include <stdio.h>
#include <string.h>
int main()
{
char s[200] = "what the hell is going on?";
printf("%d", strncmp(&s[5], "the hell",16));
return 0;
}
为什么不是显示0? 展开
#include <string.h>
int main()
{
char s[200] = "what the hell is going on?";
printf("%d", strncmp(&s[5], "the hell",16));
return 0;
}
为什么不是显示0? 展开
1个回答
展开全部
&s[5]传递给比较的字符串是“the hell is going on?”
当它与"the hell"比较时,前面的字符都相等,但是第二个串尾的结束符与第一个串中的空格符相比较就不相等了。
所以返回的是' '减去'\0'的差,即32。
当它与"the hell"比较时,前面的字符都相等,但是第二个串尾的结束符与第一个串中的空格符相比较就不相等了。
所以返回的是' '减去'\0'的差,即32。
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询