函数说明 strcasecmp()用来比较参数s1和s2字符串,比较时会自动忽略大小写的差异。

返回值 若参数s1和s2字符串相同则返回0。s1长度大于s2长度则返回大于0 的值,s1 长度若小于s2 长度则返回小于0的值.

intstrcasecmp(constchar*s1,constchar*s2){intc1,c2;do{c1=tolower(*s1++);c2=tolower(*s2++);}while(c1==c2&&c1!=0);returnc1-c2;}

函数说明:strncasecmp()用来比较参数s1和s2字符串前n个字符,比较时会自动忽略大小写的差异

返回值 :若参数s1和s2字符串相同则返回0 s1若大于s2则返回大于0的值 s1若小于s2则返回小于0的值

intstrnicmp(constchar*s1,constchar*s2,intlen){unsignedcharc1,c2;if(!len)return0;do{c1=*s1++;c2=*s2++;if(!c1||!c2)break;if(c1==c2)continue;c1=tolower(c1);c2=tolower(c2);if(c1!=c2)break;}while(--len);return(int)c1-(int)c2;}

字符串比较实现

intstrcmp(constchar*strDest,constchar*strSrc){assert((strDest!=NULL)&&(strSrc!=NULL));while(*strDest==*strSrc){if(*strDest=='\0'){return0;}++strDest;++strSrc;}return*strDest-*strSrc;}