From 4c87139ab0ec0d6f6412d7e4bff59517163cd134 Mon Sep 17 00:00:00 2001 From: Dan Buch Date: Tue, 13 Sep 2011 23:05:09 -0400 Subject: [PATCH] handling all args passed --- ex13.c | 71 ++++++++++++++++++++++++++++++---------------------------- 1 file changed, 37 insertions(+), 34 deletions(-) diff --git a/ex13.c b/ex13.c index 8ec6454..33356ad 100644 --- a/ex13.c +++ b/ex13.c @@ -2,55 +2,58 @@ int main(int argc, char *argv[]) { - if(argc != 2) { - printf("ERROR: You need one argument.\n"); + if (argc < 2) { + fprintf(stderr, "ERROR: You must provide at least one argument.\n"); return 1; } - int i = 0; + int i; + int argn; + char letter; int up_low_sep = (int)('a' - 'A'); int upper_floor = (int)'A'; int upper_ceil = (int)'Z'; - for(i = 0; '\0' != (letter = argv[1][i]); i++) { - char letter = argv[1][i]; - int i_letter = (int)letter; - if (upper_floor < i_letter && i_letter < upper_ceil) { - letter = (char)(i_letter + up_low_sep); - } + for(argn = 1; argn < argc; argn++) { + for(i = 0; '\0' != (letter = argv[argn][i]); i++) { + int i_letter = (int)letter; + if (upper_floor < i_letter && i_letter < upper_ceil) { + letter = (char)(i_letter + up_low_sep); + } - switch(letter) { - case 'a': - printf("%d: 'a'\n", i); - break; + switch(letter) { + case 'a': + printf("%d: 'a'\n", i); + break; - case 'e': - printf("%d: 'e'\n", i); - break; + case 'e': + printf("%d: 'e'\n", i); + break; - case 'i': - printf("%d: 'i'\n", i); - break; + case 'i': + printf("%d: 'i'\n", i); + break; - case 'o': - printf("%d: 'o'\n", i); - break; + case 'o': + printf("%d: 'o'\n", i); + break; - case 'u': - printf("%d: 'u'\n", i); - break; + case 'u': + printf("%d: 'u'\n", i); + break; - case 'y': - if (i > 2) { - printf("%d: 'Y'\n", i); - } else { - printf("%d: 'Y' isn't a vowel this time\n", i); - } - break; + case 'y': + if (i > 2) { + printf("%d: 'Y'\n", i); + } else { + printf("%d: 'Y' isn't a vowel this time\n", i); + } + break; - default: - printf("%d: '%c' is not a vowel\n", i, letter); + default: + printf("%d: '%c' is not a vowel\n", i, letter); + } } }