函數原型: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 編譯運行:
strcmpi與stricmp具有相同的功能。