首页 > 其他 > 详细

strcasecmp用法

时间:2021-01-07 19:02:26      阅读:31      评论:0      收藏:0      [点我收藏+]

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;
}

strcasecmp用法

原文:https://www.cnblogs.com/st17/p/14247797.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!