Check if Two Words Are Anagrams

This function checks if two words are anagrams (which means that they have the same letters, but possibly in a different order). It ignores case differences in letters.

The program counts the letters in a string by allocating a 256-byte array and storing, in index n of the array, the number of times that the letter with an ASCII value of n appears (with an adjustment for case insensitivity—all letters are upper-cased first). This means that the program can't handle more than 256 of any one letter—that is not the bug. After the letter totals for the two words are counted, they are compared to see if they match, in ...

Get Find the Bug A Book of Incorrect Programs now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.