Topics

bool equalIgnoreCase(char a, char b) {
    return (a == b) || (isalpha(a) && isalpha(b) && abs(a - b) == 32);
}

This method works because in ASCII:

  • Uppercase letters are from 65 (ā€˜Aā€™) to 90 (ā€˜Zā€™)
  • Lowercase letters are from 97 (ā€˜aā€™) to 122 (ā€˜zā€™)
  • The difference between same letters in different cases is always 32

Another simpler approach is to use tolower()

bool equalIgnoreCase(char a, char b) { return tolower(a) == tolower(b); }