strcmp without case sensitivity

from https://cboard.cprogramming.com/c-programming/63091-strcmp-without-case-sensitivity.html


int strcmpi (const char *p1, const char *p2)
{
  register unsigned char *s1 = (unsigned char *) p1;
  register unsigned char *s2 = (unsigned char *) p2;
  unsigned char c1, c2;

  do
  {
      c1 = (unsigned char) toupper((int)*s1++);
      c2 = (unsigned char) toupper((int)*s2++);
      if (c1 == '\0')
      {
            return c1 - c2;
      }
  }
  while (c1 == c2);

  return c1 - c2;
}

留言

熱門文章