-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathada_c.cpp
More file actions
84 lines (80 loc) · 2.33 KB
/
Copy pathada_c.cpp
File metadata and controls
84 lines (80 loc) · 2.33 KB
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
77
78
79
80
81
82
83
84
// Sursa Adei cu citire din stdio
// Scrierea e tot cu stdio
#include <fstream>
#include <string>
#include <cstdio>
using namespace std;
int main() {
ofstream g;
FILE * pIn = fopen("convertor.in", "r");
FILE * pOut = fopen("convertor.out", "w");
g.open("convertor.out");
// identificare chei
char c;
string buffer;
int pos;
int state = 0;
while ((c = fgetc(pIn)) && c != EOF && (c!='}')) {
if ((c == '[') && (state == 0))
state = 1;
else if ((c == '{') && (state == 1))
state = 2;
else if ((c == '\"') && (state == 2))
state = 3;
else if ((c == '\"') && (state == 3)) {
state = 2;
fputs(buffer.c_str(), pOut);
fputc(',', pOut);
// g << buffer << ",";
buffer = "";
} else if ((c == ':') && (state == 2))
state = 4;
else if ((c == ',') && (state == 4))
state = 2;
else if (state == 3)
buffer += c;
}
fputc('\n', pOut);
// g<<"\n";
fseek(pIn, 0, SEEK_END);
rewind(pIn);
state = 0;
while ((c = fgetc(pIn)) && c != EOF && (c!=']')) {
if ((c == '[') && (state == 0))
state = 1;
else if ((c == '{') && (state == 1))
state = 2;
else if ((c == '\"') && (state == 2))
state = 3;
else if ((c == '\"') && (state == 3))
state = 2;
else if ((c == ':') && (state == 2))
state = 4;
else if ((c == '\"') && (state == 4))
state = 5;
else if ((c == '\"') && (state == 5))
state = 4;
else if ((c == ',') && (state == 4)) {
state = 2;
fputs(buffer.c_str(), pOut);
fputc(',', pOut);
// g << buffer << ",";
buffer = "";
} else if ((c == '}') && (state == 4)) {
state = 1;
fputs(buffer.c_str(), pOut);
fputc(',', pOut);
// g << buffer << ",";
buffer = "";
} else if ((c == '}') && (state = 2))
state = 1;
else if ((c == ',') && (state = 1))
// g << "\n";
fputc('\n', pOut);
else if (state == 5)
buffer += c;
else if ((isdigit(c)) && (state == 4))
buffer += c;
}
return 0;
}