Monday, October 10, 2011

Enhanced telephone digits

Example 5-5 in the textbook (pp 241-242) asks the user to enter an uppercase character and returns the corresponding number from the telephone keypad. If you would prefer to make the code case-insensitive, you could add the following to the program in the book.

// above the #includes
#define TO_UPPER_CONSTANT 32


// above the while loop's guard
if ( c >= 'a' && c <= 'z' )
    c -= TO_UPPER_CONSTANT;