-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.cpp
60 lines (50 loc) · 1.05 KB
/
main.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
#include <iostream>
#include <fstream>
bool isLetter(char c)
{
return (c >= 'A' && c <= 'Z') || (c >= 'a' && c <= 'z') || c == '_';
}
bool isAlphanumerical(char c)
{
return (c >= '0' && c <= '9') || isLetter(c);
}
int main(int argc, char* argv[])
{
if(argc == 1)
{
std::cout << "No filename in command line found." << '\n'
<< "Usage: " << argv[0] << " filename" << '\n';
std::cout << "Press Enter to continue . . . ";
std::cin.get();
return 0;
}
std::ifstream source(argv[1]);
if (!source) //Error checking
{
std::cout << "File " << argv[1] << " not found." << '\n';
std::cout << "Press Enter to continue . . . ";
std::cin.get();
return 0;
}
char ch;
bool nameFound{ false };
while(source.get(ch))
{
if (isLetter(ch))
{
std::cout << ch;
nameFound = true;
}
else if (nameFound && isAlphanumerical(ch))
std::cout << ch;
else if(nameFound)
{
nameFound = false;
std::cout << '\n';
}
}
std::cout << '\n';
std::cout << "Press Enter to continue . . . ";
std::cin.get();
return 0;
} //source.close()