Modifications to ex10
This commit is contained in:
parent
8f9842ddfb
commit
353b77271d
38
lcthw/ex10.c
38
lcthw/ex10.c
@ -2,48 +2,53 @@
|
||||
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
if (argc != 2) {
|
||||
printf("ERROR: You need one argument.\n");
|
||||
if (argc < 2) {
|
||||
printf("ERROR: You need at least one argument.\n");
|
||||
// this is how you abort a program
|
||||
return 1;
|
||||
}
|
||||
|
||||
int i = 0;
|
||||
for (i = 0; argv[1][i] != '\0'; i++) {
|
||||
char letter = argv[1][i];
|
||||
int arg = 1;
|
||||
for (arg = 1; arg < argc; arg++) {
|
||||
for (i = 0; argv[arg][i] != '\0'; i++) {
|
||||
printf("(%d) ", arg);
|
||||
|
||||
char letter = argv[arg][i];
|
||||
|
||||
// lowercase letters
|
||||
if (letter >= 'A' && letter <= 'Z') {
|
||||
letter += ('a' - 'A');
|
||||
}
|
||||
|
||||
switch (letter) {
|
||||
case 'a':
|
||||
case 'A':
|
||||
printf("%d: 'A'\n", i);
|
||||
printf("%d: 'a'\n", i);
|
||||
break;
|
||||
|
||||
case 'e':
|
||||
case 'E':
|
||||
printf("%d: 'E'\n", i);
|
||||
printf("%d: 'e'\n", i);
|
||||
break;
|
||||
|
||||
case 'i':
|
||||
case 'I':
|
||||
printf("%d: 'I'\n", i);
|
||||
printf("%d: 'i'\n", i);
|
||||
break;
|
||||
|
||||
case 'o':
|
||||
case 'O':
|
||||
printf("%d: 'O'\n", i);
|
||||
printf("%d: 'o'\n", i);
|
||||
break;
|
||||
|
||||
case 'u':
|
||||
case 'U':
|
||||
printf("%d: 'U'\n", i);
|
||||
printf("%d: 'u'\n", i);
|
||||
break;
|
||||
|
||||
case 'y':
|
||||
case 'Y':
|
||||
// why i > 2? is this a bug?
|
||||
if (i > 2) {
|
||||
// it's only sometimes Y
|
||||
printf("%d: 'Y'\n", i);
|
||||
printf("%d: 'y'\n", i);
|
||||
} else {
|
||||
printf("%d: %c is not a vowel\n", i, letter);
|
||||
}
|
||||
break;
|
||||
|
||||
@ -51,6 +56,7 @@ int main(int argc, char *argv[])
|
||||
printf("%d: %c is not a vowel\n", i, letter);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user