-
Notifications
You must be signed in to change notification settings - Fork 1
/
ex13-1.c
61 lines (48 loc) · 1.14 KB
/
ex13-1.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
#include <stdio.h>
/////////////////////////////////////////////////////////
// Exercise 13 - Extra Credit #1
// Convert the upper case characters to lower case and
// remove upper case characters from the switch block.
/////////////////////////////////////////////////////////
int main(int argc, char *argv[])
{
if(argc != 2) {
printf("ERROR: please enter exactly one argument.\n");
return 1;
}
int i = 0;
for(i = 0; argv[1][i] != '\0'; i++) {
char letter = argv[1][i];
char orig_letter = letter;
if(letter >= 'A' && letter <= 'Z') {
// PROTIP: man ascii
letter += 32;
}
switch(letter) {
case 'a':
printf("%d: '%c'\n", i, orig_letter);
break;
case 'e':
printf("%d: '%c'\n", i, orig_letter);
break;
case 'i':
printf("%d: '%c'\n", i, orig_letter);
break;
case 'o':
printf("%d: '%c'\n", i, orig_letter);
break;
case 'u':
printf("%d: '%c'\n", i, orig_letter);
break;
case 'y':
if(i > 2) {
// it's only sometimes Y
printf("%d: '%c'\n", i, orig_letter);
}
break;
default:
printf("%d: '%c' is not a vowel\n", i, orig_letter);
}
}
return 0;
}