Previous: 4.5 Menu Driven Programs
Up: 4 Processing Character Data
Next: 4.7 Summary
Previous Page: 4.5 Menu Driven Programs
Next Page: 4.7 Summary
if ('a' <= ch <= 'z') /* should be ('a' <= ch && ch <= 'z') */ ...The operators are evaluated left to right: 'a' <= ch is either True or False, i.e. 1 or 0. This value is compared with 'z' and the result is always True.
char find_next(char c) { char next;Suppose c is 'z'. The variable next is assigned an 'a' and control passes to the next statement which assigns c + 1 to next. In fact, the function always returns c + 1 no matter what c is.switch(c) { case 'z': next = 'a'; default: next = c + 1; } return next; }