函数名:memcmp
头文件:
函数原型: void* memcmp(void *s1,void *s2,unsigned m);
功能:比较m字节长的两个字符串s1和s2
参数: s1 和 s2 为要比较的字符串
unsigned m 为要比较的前m个字节
返回值:s1
s1=s2 返回等于0
s1>s2 返回1
程序例:比较给定的字符串s1和s2的大小,并将结果输出#include
#include
#include
int main(void){
char *s1="I love www.dotcpp.com!";
char *s2="I like www.dotcpp.com!";
int* t = (int*)memcmp(s1,s2,strlen(s1));
if(!t){
printf("s1 is the same as s2\n");
}else if(t>0){
printf("s1 is great than s2\n");
}else{
printf("s1 is less than s2\n");
}
return 0;
}
运行结果s1 is great than s2