Dotcpp  >  编程教程  >  mem.h头文件  >  C语言memicmp()函数:比较s1和s2的前m个字节

C语言memicmp()函数:比较s1和s2的前m个字节

点击打开在线编译器,边学边练

函数名:memicmp

头文件:<mem.h>

函数原型: int memicmp(void *s1,void *s2,unsigned m);

功能:比较s1和s2的前m个字节,忽略字符的大写或小写

参数: s1 和 s2 为要比较的字符串 

           unsigned m  为要比较的前m个字节

返回值:s1>s2   返回1

             s1=s2   返回等于0

             s1<s2   返回-1


程序例:以忽略大小写的方式比较给定的字符串s1和s2的前6个字符。

#include<stdio.h>

#include<mem.h>

#include<string.h>

int main(void){

   char *s1="I love www.dotcpp.com!";

   char *s2="I LOVa www.dotcpp.com!";

   int t = memicmp(s1,s2,6);

   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 the same as s2



本文固定URL:https://www.dotcpp.com/course/493

C语言函数库
assert.h头文件
ctype.h头文件
float.h头文件
io.h头文件
math.h头文件
mem.h头文件
setjmp.h头文件
stdio.h头文件
stdlib.h头文件
sigal.h头文件
string.h头文件
time.h头文件
Dotcpp在线编译      (登录可减少运行等待时间)