Modifications to ex10

This commit is contained in:
Dan Buch 2024-04-16 21:10:49 -04:00
parent 8f9842ddfb
commit 353b77271d
Signed by: meatballhat
GPG Key ID: A12F782281063434

View File

@ -2,53 +2,59 @@
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"); printf("ERROR: You need at least one argument.\n");
// this is how you abort a program // this is how you abort a program
return 1; return 1;
} }
int i = 0; int i = 0;
for (i = 0; argv[1][i] != '\0'; i++) { int arg = 1;
char letter = argv[1][i]; for (arg = 1; arg < argc; arg++) {
for (i = 0; argv[arg][i] != '\0'; i++) {
printf("(%d) ", arg);
switch (letter) { char letter = argv[arg][i];
case 'a':
case 'A':
printf("%d: 'A'\n", i);
break;
case 'e': // lowercase letters
case 'E': if (letter >= 'A' && letter <= 'Z') {
printf("%d: 'E'\n", i); letter += ('a' - 'A');
break; }
case 'i': switch (letter) {
case 'I': case 'a':
printf("%d: 'I'\n", i); printf("%d: 'a'\n", i);
break; break;
case 'o': case 'e':
case 'O': printf("%d: 'e'\n", i);
printf("%d: 'O'\n", i); break;
break;
case 'u': case 'i':
case 'U': printf("%d: 'i'\n", i);
printf("%d: 'U'\n", i); break;
break;
case 'y': case 'o':
case 'Y': printf("%d: 'o'\n", i);
// why i > 2? is this a bug? break;
if (i > 2) {
// it's only sometimes Y
printf("%d: 'Y'\n", i);
}
break;
default: case 'u':
printf("%d: %c is not a vowel\n", i, letter); printf("%d: 'u'\n", i);
break;
case 'y':
// why i > 2? is this a bug?
if (i > 2) {
// it's only sometimes Y
printf("%d: 'y'\n", i);
} else {
printf("%d: %c is not a vowel\n", i, letter);
}
break;
default:
printf("%d: %c is not a vowel\n", i, letter);
}
} }
} }