handling all args passed

This commit is contained in:
Dan Buch 2011-09-13 23:05:09 -04:00
parent d85c6d97eb
commit 4c87139ab0

71
ex13.c
View File

@ -2,55 +2,58 @@
int main(int argc, char *argv[]) int main(int argc, char *argv[])
{ {
if(argc != 2) { if (argc < 2) {
printf("ERROR: You need one argument.\n"); fprintf(stderr, "ERROR: You must provide at least one argument.\n");
return 1; return 1;
} }
int i = 0; int i;
int argn;
char letter; char letter;
int up_low_sep = (int)('a' - 'A'); int up_low_sep = (int)('a' - 'A');
int upper_floor = (int)'A'; int upper_floor = (int)'A';
int upper_ceil = (int)'Z'; int upper_ceil = (int)'Z';
for(i = 0; '\0' != (letter = argv[1][i]); i++) { for(argn = 1; argn < argc; argn++) {
char letter = argv[1][i]; for(i = 0; '\0' != (letter = argv[argn][i]); i++) {
int i_letter = (int)letter; int i_letter = (int)letter;
if (upper_floor < i_letter && i_letter < upper_ceil) { if (upper_floor < i_letter && i_letter < upper_ceil) {
letter = (char)(i_letter + up_low_sep); letter = (char)(i_letter + up_low_sep);
} }
switch(letter) { switch(letter) {
case 'a': case 'a':
printf("%d: 'a'\n", i); printf("%d: 'a'\n", i);
break; break;
case 'e': case 'e':
printf("%d: 'e'\n", i); printf("%d: 'e'\n", i);
break; break;
case 'i': case 'i':
printf("%d: 'i'\n", i); printf("%d: 'i'\n", i);
break; break;
case 'o': case 'o':
printf("%d: 'o'\n", i); printf("%d: 'o'\n", i);
break; break;
case 'u': case 'u':
printf("%d: 'u'\n", i); printf("%d: 'u'\n", i);
break; break;
case 'y': case 'y':
if (i > 2) { if (i > 2) {
printf("%d: 'Y'\n", i); printf("%d: 'Y'\n", i);
} else { } else {
printf("%d: 'Y' isn't a vowel this time\n", i); printf("%d: 'Y' isn't a vowel this time\n", i);
} }
break; break;
default: default:
printf("%d: '%c' is not a vowel\n", i, letter); printf("%d: '%c' is not a vowel\n", i, letter);
}
} }
} }