常用的C语言库函数达成
发布时间:2021-12-08 19:00:17 所属栏目:教程 来源:互联网
导读:函数说明 strcasecmp()用来比较参数s1和s2字符串,比较时会自动忽略大小写的差异。 返回值 若参数s1和s2字符串相同则返回0。s1长度大于s2长度则返回大于0 的值,s1 长度若小于s2 长度则返回小于0的值。 int strcasecmp(const char *s1, const char *s2) { in
函数说明 strcasecmp()用来比较参数s1和s2字符串,比较时会自动忽略大小写的差异。 返回值 若参数s1和s2字符串相同则返回0。s1长度大于s2长度则返回大于0 的值,s1 长度若小于s2 长度则返回小于0的值。 int strcasecmp(const char *s1, const char *s2) { int c1, c2; do { c1 = tolower(*s1++); c2 = tolower(*s2++); } while(c1 == c2 && c1 != 0); return c1 - c2; } 函数说明:strncasecmp()用来比较参数s1和s2字符串前n个字符,比较时会自动忽略大小写的差异 返回值 :若参数s1和s2字符串相同则返回0 s1若大于s2则返回大于0的值 s1若小于s2则返回小于0的值 int strnicmp(const char *s1, const char *s2, int len) { unsigned char c1, c2; if(!len) return 0; 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; } 字符串比较实现 int strcmp(const char* strDest,const char* strSrc) { assert((strDest != NULL) && (strSrc != NULL)); while (*strDest == *strSrc) { if (*strDest == ' |