Dotcpp  >  编程教程  >  string.h头文件  >  C语言stricmp()函数:比较两个字符串大小

C语言stricmp()函数:比较两个字符串大小

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

函数名: stricmp

头文件:<string.h>

函数原型: int stricmp(const char *str1, const char *str2);

功 能: 比较两个字符串大小,但不区分大小写

参 数: str1和str2为要比较的两个字符串 

返回值: str1>str2   返回1;

               str1==str2  返回0;

               str1<str2   返回-1;


程序例: 比较字符串buf1和字符串buf2的大小,并输出结果

#include <string.h>

#include <stdio.h>

int main(void) {

   char *buf1 = "WWW.DOTCPP.COM", *buf2 = "www.dotcpp.com";

   int ptr = stricmp(buf2, buf1);

   if (ptr > 0) {

      printf("buffer 2 is greater than buffer 1\n");

   }

   if (ptr < 0){

      printf("buffer 2 is less than buffer 1\n");

   }

   if (ptr == 0) {

      printf("buffer 2 equals buffer 1\n");

   }

   return 0;

}

 

运行结果:

buffer 2 equals buffer 1



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

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在线编译      (登录可减少运行等待时间)