首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 开发语言 > C语言 >

strcmp函数,为何这样输入,输出结果为1

2013-09-08 
strcmp函数,为什么这样输入,输出结果为1?#include stdio.h#include string.hint main(void){int ncha

strcmp函数,为什么这样输入,输出结果为1?

#include <stdio.h>
#include <string.h>
int main(void)
{
int n;
char str1[20],str2[20];
gets_s (str1);
gets_s (str2);
n = strcmp (str1,str2);
printf_s ("%d\n",n);
}

运行时,如果输入abcd和abc,为什么输出结果为1?
[解决办法]
这是strcmp函数的实现机制决定的,如果改用strncmp(str1,str2, 3);那么结果又是另一种。

热点排行