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