strcmpi,stricmp函数

函数原型:extern int strcmpi(char *str1,char * str2)

                   或者 extern int stricmp(char *str1,char * str2)

参数说明:str1为第一个要比较的字符串,str2为第二个要比较的字符串。
        
所在库名:#include <string.h>
  
函数功能:比较字符串str1和str2,但是不区分字母的大小写(这点就是与strcmp的区别)。

返回说明:返回整数值:当str1<str2时,返回值<0; 当str1=str2时,返回值=0; 当str1>str2时,返回值>0。

其它说明:暂时无。

实例:

第一种情形:

#include <string.h>
#include 
<stdio.h>
int main()
{
    
char *str1="SKY2098!";
    
char *str2="sky2098,I like writing!";   //str1与str2的大小写不一样,而且长度不同

    
int inttemp;

    inttemp
=strcmpi(str1,str2);   //将字符串比较的返回值保存在int型变量inttemp中,用strcmpi函数
    if(inttemp<0)
    
{
        printf(
"lexicographic(str1) < lexicographic(str2) ");
    }

    
else if(inttemp>0)
        
{
            printf(
"lexicographic(str1) > lexicographic(str2) ");
        }

        
else
        
{
            printf(
"lexicographic(str1) == lexicographic(str2) ");
        }

    
return 0;
}

在VC++ 6.0 编译运行:

显然当str1与str2比较后,由于str1是str2的子串,故而str2的字典序比str1要大,返回值<0。

第二种情形:

#include <string.h>
#include 
<stdio.h>
int main()
{
    
char *str1="SKY2098,I liKE wrITing!";
    
char *str2="sky2098,I like writing!";   //str1与str2的大小写不一样,但是代表的含义一样,也就是str1的字典序与str2相同,不区分大小写
    int inttemp;

    inttemp
=strcmpi(str1,str2);   //将字符串比较的返回值保存在int型变量inttemp中,用strcmpi函数
    if(inttemp<0)
    
{
        printf(
"lexicographic(str1) < lexicographic(str2) ");
    }

    
else if(inttemp>0)
        
{
            printf(
"lexicographic(str1) > lexicographic(str2) ");
        }

        
else
        
{
            printf(
"lexicographic(str1) == lexicographic(str2) ");
        }

    
return 0;
}

在VC++ 6.0 编译运行:

posted @ 2012-11-02 08:20  N3verL4nd  阅读(449)  评论(0编辑  收藏  举报