Skip to content

Commit

Permalink
ex10: Remove uppercase switch cases (p. 45)
Browse files Browse the repository at this point in the history
Cheating a bit by using tolower(3) instead of simple (but nonsemantic)
ASCII character arithmetic like the book wanted.
  • Loading branch information
larryv committed Apr 5, 2016
1 parent 2f1dc99 commit 369444e
Showing 1 changed file with 2 additions and 7 deletions.
9 changes: 2 additions & 7 deletions ex10.c
Expand Up @@ -3,6 +3,7 @@
Prints each of its arguments' letters and whether it's a vowel.
*/

#include <ctype.h>
#include <stdio.h>

int main(int argc, char *argv[])
Expand All @@ -20,22 +21,16 @@ int main(int argc, char *argv[])
for (i = 1; i < argc; i++) {
for (j = 0, letter = argv[i][j]; letter != '\0'; letter = argv[i][++j]) {
printf("argv[%d][%d]: '%c' is ", i, j, letter);
switch (letter) {
switch (tolower(letter)) {
case 'a':
case 'A':
case 'e':
case 'E':
case 'i':
case 'I':
case 'o':
case 'O':
case 'u':
case 'U':
printf("a vowel");
break;

case 'y':
case 'Y':
if (j > 2) {
// it's only sometimes Y
printf("a vowel");
Expand Down

0 comments on commit 369444e

Please sign in to comment.