strcasecmp用法

strcasecmp

忽略大小写字符串比较函数

#include <strings.h>

int strcasecmp(const char *s1, const char *s2);

参数为两个需要比较的字符串

返回值

0: 相同
非0: 返回第一个不同的字符相差的数量。

实例

#include <stdio.h>

int main

glibc-2.32中函数实现

/* Compare S1 and S2, ignoring case, returning less than, equal to or
   greater than zero if S1 is lexicographically less than,
   equal to or greater than S2.  */
int
__strcasecmp (const char *s1, const char *s2 LOCALE_PARAM)
{
#if defined _LIBC && !defined USE_IN_EXTENDED_LOCALE_MODEL
  locale_t loc = _NL_CURRENT_LOCALE;
#endif
  const unsigned char *p1 = (const unsigned char *) s1;
  const unsigned char *p2 = (const unsigned char *) s2;
  int result;

  if (p1 == p2)
    return 0;

  while ((result = TOLOWER (*p1) - TOLOWER (*p2++)) == 0)
    if (*p1++ == '\0')
      break;

  return result;
}
posted @ 2021-01-07 17:54  十七-2020  阅读(409)  评论(0)    收藏  举报