C语言之比较字符串strcmp/strncmp
代码示例:
#include <stdio.h>
#include <string.h>
int main()
{
char str1 []="I Love FishC.com !";
//char str2 []="I Love FishC.com !";
char str2 []="I Love Fishc.com !";
if(!strcmp(str1,str2))
{
printf("两个字符串完全一致!\n");
}
else
printf("两个字符串不一致!\n");
return 0;
}
执行示例:
[liangjian@localhost ~]$ cat test17.c
#include <stdio.h>
#include <string.h>
int main()
{
char str1 []="I Love FishC.com !";
char str2 []="I Love FishC.com !";
//char str2 []="I Love Fishc.com !";
if(!strcmp(str1,str2))
{
printf("两个字符串完全一致!\n");
}
else
printf("两个字符串不一致!\n");
//strcat(str1,str2);
//printf("str1: %s \n",str1);
return 0;
}
[liangjian@localhost ~]$ gcc test17.c &&./a.out
两个字符串完全一致!
[liangjian@localhost ~]$