-
Notifications
You must be signed in to change notification settings - Fork 1
/
ex13.c
60 lines (49 loc) · 1.04 KB
/
ex13.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
#include <stdio.h>
int main(int argc, char *argv[])
{
if(argc != 2) {
printf("ERROR: You need one argument.\n");
// this is how you abort a program;
return 1;
}
int i = 0;
char letter;
// Extra credit #2 - using ',' initialize the letter in the for loop
for(i = 0, letter = argv[1][i]; letter != '\0'; letter = argv[1][++i]) {
switch(letter) {
case 'a':
case 'A':
printf("%d: 'A'\n", i);
break;
case 'e':
case 'E':
printf("%d: 'E'\n", i);
break;
case 'i':
case 'I':
printf("%d: 'I'\n", i);
break;
case 'o':
case 'O':
printf("%d: 'O'\n", i);
break;
case 'u':
case 'U':
printf("%d: 'U'\n", i);
break;
case 'y':
case 'Y':
if(i > 2) {
// it's only sometimes Y
printf("%d: 'Y'\n", i);
// Extra credit #5 - moved the break up here so that
// the Y character falls through to "default" case
// when it is the first character in the word.
break;
}
default:
printf("%d: %c is not a vowel\n", i, letter);
}
}
return 0;
}