-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathbig_switch.cpp
55 lines (47 loc) · 1.46 KB
/
big_switch.cpp
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
#include <stdio.h>
#include <string.h>
#define IS_a_TO_Z 'a': case 'b': case 'c': case 'd': case 'e': case 'f': case 'g': case 'h': case 'i': case 'j': case 'k': \
case 'l': case 'm': case 'n': case 'o': case 'p': case 'q': case 'r': case 's': case 't': case 'u': \
case 'v': case 'w': case 'x': case 'y': case 'z': case 'A': case 'B': case 'C': case 'D': case 'E': \
case 'F': case 'G': case 'H': case 'I': case 'J': case 'K': case 'L': case 'M': case 'N': case 'O': \
case 'P': case 'Q': case 'R': case 'S': case 'T': case 'U': case 'V': case 'W': case 'X': case 'Y': \
case 'Z'
#define IS_NUM '0': case '1': case '2': case '3': case '4': \
case '5': case '6': case '7': case '8': case '9'
void print_usage(const char* szName)
{
printf("%s [string with alpha, num, and special chars]\n This program will identifiy each character type\n", szName);
}
void check_current_char(char c)
{
switch( c )
{
case IS_a_TO_Z:
printf("%c is ALPHA\n", c);
break;
case IS_NUM:
printf("%c is NUM\n", c);
break;
default:
printf("%c is SPECIAL\n", c);
}
}
void check_string(const char* szString)
{
int length = strlen(szString);
for ( int i=0; i<length; i++)
{
check_current_char(szString[i]);
}
}
int main (int argc, const char* argv[])
{
if ( 1 < argc )
{
check_string(argv[1]);
}
else
{
print_usage(argv[0]);
}
}