C标准库 stricmp函数

stricmp()函数用于字符串的比较,不区分大小写。

stricmp()函数 语法

int stricmp(const char*s1,const char*s2);

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

stricmp()函数的返回值情况:若字符串s1和s2相同,则返回0;若s1大于s2,则返回大于0的值;若s1小于s2,则返回小于0的值。

stricmp()函数 示例

本示例使用stricmp函数比较字符串s1和s2,不区分大小写,并输出比较的结果。其具体代码如下所示:

#include<string.h>
#include<stdio.h>
int main(void)
{
     char*s1="CoN",*s2="cON";/*声明要比较的字符串*/
     int p;
     p=stricmp(s2,s1);/*比较字符串*/
     if(p>0)
         printf("s2 is greater than s1 ");/*输出比较结果*/
     if(p<0)
         printf("s2 is less than s1 ");/*输出比较结果*/
     if(p==0)
         printf("s2 equals s1 ");/*输出比较结果*/
     return 0;
}

运行结果如图所示。

stricmp()函数 示例


赞(0)
未经允许不得转载:极客笔记 » C标准库 stricmp函数

评论 抢沙发

  • 昵称 (必填)
  • 邮箱 (必填)
  • 网址