strcmp函数
字符串比较函数
头文件:#include<string.h>
函数声明:int strcmp(const char*s1,const char*s2);
函数说明:比较s1和s2指向的字符串的大小,比较方法:逐个字符去比较ascll码,一旦比较出大小返回
如果所有字符都一样,则返回0返回值:
如果·s1指向的字符串大于s2指向的字符串 返回1
如果·s1指向的字符串小于s2指向的字符串 返回-1
如果相等的话返回0
#include<stdio.h>
#include<string.h>
#pragma warning(disable:4996)
int main()
{
char *str1=”hello world”;
char *str2=”hello kitty”;
int ret;
ret = strcmp(str1,str2);
if(ret > 0)
printf(“str1指向的字符串大于str2指向的字符串\n”);
else if(ret <0)
printf(“str1指向的字符串小于str2指向的字符串\n”);
else printf(“两个字符串相等\n”);
return 0;
}