-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathe14.cpp
76 lines (70 loc) · 1.06 KB
/
e14.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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
#include "../std_lib.h"
using namespace std;
static map<string, int> classify_map;
void classify (char c)
{
if (isspace(c))
{
classify_map["isspace"]++;
}
if (isalpha(c))
{
classify_map["isalpha"]++;
}
if (isdigit(c))
{
classify_map["isdigit"]++;
}
if (isxdigit(c))
{
classify_map["isxdigit"]++;
}
if (isupper(c))
{
classify_map["isupper"]++;
}
if (isalnum(c))
{
classify_map["isalnum"]++;
}
if (iscntrl(c))
{
classify_map["iscntrl"]++;
}
if (ispunct(c))
{
classify_map["ispunct"]++;
}
if (isprint(c))
{
classify_map["isprint"]++;
}
if (isgraph(c))
{
classify_map["isgraph"]++;
}
}
int main ()
try
{
string filename {"Makefile"};
ifstream ifs {filename};
if (!ifs)
{
throw runtime_error("can't open file '" + filename + "'");
}
char c;
while (!ifs.eof())
{
ifs.get(c);
classify(c);
}
for (auto &m : classify_map)
{
cout << setw(10) << left << m.first + ":" << m.second << endl;
}
}
catch (exception &e)
{
cerr << "Error: " << e.what() << endl;
}