函数说明 strcasecmp()用来比较参数s1和s2字符串,比较时会自动忽略大小写的差异。
返回值 若参数s1和s2字符串相同则返回0。s1长度大于s2长度则返回大于0 的值,s1 长度若小于s2 长度则返回小于0的值.
首先给出这两个函数的具体实现:
47 /*****************************************************************************/ 48 /* STRCASECMP() - Case-insensitive strcmp. */ 49 /*****************************************************************************/ 50 static int strcasecmp(const char* s1, const char* s2) 51 { 52 char c1, c2; 53 do { c1 = *s1++; c2 = *s2++; } 54 while (c1 && c2 && (tolower(c1) == tolower(c2))); 55 56 return tolower(c1) - tolower(c2); 57 } 58 59 /*****************************************************************************/ 60 /* STRNCASECMP() - Case-insensitive strncmp. */ 61 /*****************************************************************************/ 62 static int strncasecmp(const char* s1, const char* s2, size_t n) 63 { 64 char c1, c2; 65 66 if (!n) return 0; 67 68 do { c1 = *s1++; c2 = *s2++; } 69 while (--n && c1 && c2 && (tolower(c1) == tolower(c2))); 70 71 return tolower(c1) - tolower(c2); 72 }
函数说明:strncasecmp()用来比较参数s1和s2字符串前n个字符,比较时会自动忽略大小写的差异
返回值 :若参数s1和s2字符串相同则返回0 s1若大于s2则返回大于0的值 s1若小于s2则返回小于0的值
字符串比较--strcasecmp()和strncasecmp()
原文:http://blog.csdn.net/yusiguyuan/article/details/18354643