淡泊明志 宁静致远
分类: C/C++
2006-11-24 08:50:35
【C语言库函数源代码】
【本程序在Dev C++ 4.9.9.2 下编译通过】
/*
_stricmp/_strcmpi
perform a case-insensitive string comparision.
字符串比较函数,比较字符串src和dst,但是不区分大小写,
*/
int my_stricmp(const char *dst, const char *src)
{
int ch1, ch2;
do
{
if ( ((ch1
= (unsigned char)(*(dst++)))
>= 'A') &&(ch1 <= 'Z') )
ch1 += 0x20;
if ( ((ch2
= (unsigned char)(*(src++)))
>= 'A') &&(ch2 <= 'Z') )
ch2 += 0x20;
} while ( ch1
&& (ch1 == ch2) );
return(ch1 -
ch2);
}
void Print(char * str1,char *str2,int t)
{
if(t > 0)
printf("\n%s Upper Than
%s\n",str1,str2);
else if(t < 0)
printf("\n%s Lower Than %s\n",str1,str2);
else
printf("\n%s Equal
%s\n",str1,str2);
}
int main()
{
char *str1=
"ammana";
char *str2 =
"babi";
char *str3 =
"AMMANA";
char *str4 =
"bab_";
Print(str1,str2,my_stricmp(str1,str2));
Print(str3,str1,my_stricmp(str3,str1));
Print(str4,str2,my_stricmp(str4,str2));
system("pause");
return 0;
}