-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathex13-2.c
68 lines (52 loc) · 1.26 KB
/
ex13-2.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
#include <stdio.h>
/////////////////////////////////////////////////////////
// Exercise 13 - Extra Credit #2
// Process all the arguments with another for loop.
//////////////////////////////////////////////////////////
int main(int argc, char *argv[])
{
if(argc == 1) {
printf("ERROR: please enter one or more argument.\n");
return 1;
}
int i;
for(i = 1; i < argc; i++) {
char *param = argv[i];
int j;
for(j = 0; param[j] != '\0'; j++) {
char letter = param[j];
char orig_letter = letter;
if(letter >= 'A' && letter <= 'Z') {
// PROTIP: man ascii
letter += 32;
}
switch(letter) {
case 'a':
printf("%d: '%c'\n", j, orig_letter);
break;
case 'e':
printf("%d: '%c'\n", j, orig_letter);
break;
case 'i':
printf("%d: '%c'\n", j, orig_letter);
break;
case 'o':
printf("%d: '%c'\n", j, orig_letter);
break;
case 'u':
printf("%d: '%c'\n", j, orig_letter);
break;
case 'y':
if(i > 2) {
// it's only sometimes Y
printf("%d: '%c'\n", j, orig_letter);
}
break;
default:
printf("%d: '%c' is not a vowel\n", j, orig_letter);
}
}
if(i + 1 != argc) { printf("\n"); } // don't print on last parameter
}
return 0;
}