-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.cpp
75 lines (61 loc) · 1.02 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
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
#include <iostream>
#include <fstream>
using namespace std;
void error(int l, int i) {
cout << "Error at line: " << l << ", column: " << i << endl << "Invalid Character";
}
int main(int argc, char** argv)
{
for (int j = 0; j < argc; j++) {
char accumulator = 0;
ifstream input;
input.open(argv[j], ios::in);
std::string text;
char c;
int i = 0;
int l = 1;
unsigned int ptr = 0;
while (true)
{
c = input.get();
i++;
if (c == '\n') {
l++;
i = 0;
continue;
}
if (c == EOF) {
break;
}
if (c != 'O' && c != 'R' && c != '&') {
error(l, i);
break;
}
if (c == 'O') {
ptr++;
while (ptr > text.length()) text += ' ';
}
if (c == 'R') {
if (input.get() != 'E') {
error(l, i);
break;
}
else {
accumulator++;
}
}
if (c == '&') {
if (input.get() != 'O') {
error(l, i);
break;
}
else {
text[ptr - 1] = accumulator;
accumulator = 0;
}
}
}
cout << text.c_str();
}
return 0;
}