-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.c
executable file
·174 lines (155 loc) · 2.55 KB
/
main.c
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
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
#include <stdio.h>
#include <stdlib.h>
int isNumber(char c);
int isAlpha(char c);
int append(char tempS[], char variables[][100], int line);
int clean(char *tempS, int size);
void display(const char variables[][100], int line);
int equals(char tmp[100], char line[100]);
int main()
{
char variables[100][100] = {"\0"};
int i = 0, tmp = 0;
char msg[100];
char tempS[100] = "";
int tempN;
int currLine = 0;
gets(msg);
goto E0;
E0:
if (isAlpha(msg[i]) == 1)
{
tempS[tmp] = msg[i];
i++;
tmp++;
goto E1;
}
else if (isNumber(msg[i]) == 1)
{
tempN = msg[i] - '0';
i++;
goto E2;
}
else if (msg[i] == '\0')
{
display(variables, currLine);
exit(0);
}
else if (msg[i] == ' ')
{
i++;
goto E0;
}
E1:
if (msg[i] == '\0')
{
currLine = append(tempS, variables, currLine);
tmp = clean(tempS, tmp);
goto E0;
}
else if (msg[i] == ' ')
{
currLine = append(tempS, variables, currLine);
tmp = clean(tempS, tmp);
i++;
goto E0;
}
else
{
tempS[tmp] = msg[i];
i++;
tmp++;
goto E1;
}
E2:
if (msg[i] == '\0')
{
printf("N(%d)\n", tempN);
goto E0;
}
else if (isAlpha(msg[i]) == 1)
{
printf("N(%d)\n", tempN);
goto E0;
}
else if (msg[i] == ' ')
{
printf("N(%d)\n", tempN);
i++;
goto E0;
}
else if (isNumber(msg[i]) == 1)
{
tempN = tempN * 10 + (msg[i] - '0');
i++;
goto E2;
}
}
int isNumber(char c)
{
if (c >= '0' && c <= '9')
{
return 1;
}
return 0;
}
int isAlpha(char c)
{
if (c >= 'A' && c <= 'Z')
{
return 1;
}
if (c >= 'a' && c <= 'z')
{
return 1;
}
return 0;
}
int equals(char tmp[100], char line[100])
{
int result = 1;
for (int k = 0; tmp[k] != '\0' || line[k] != '\0'; k++)
{
if (tmp[k] != line[k])
{
result = 0;
return result;
}
}
return result;
}
int append(char tempS[], char variables[][100], int line)
{
int found = 0;
for (int p = 0; p <= line; p++)
{
if (equals(tempS, variables[p]) == 1)
{
found = 1;
printf("Found at V(%d)\n", p);
}
}
if (found == 0)
{
for (int c = 0; variables[line][c] = tempS[c]; c++)
;
printf("Created at V(%d)\n", line);
line++;
}
return line;
}
int clean(char *tempS, int size)
{
for (int i = 0; i <= size; i++)
*(tempS + i) = 0;
return 0;
}
void display(const char variables[][100], int line)
{
printf("\nList of variables\n");
for (int i = 0; i < line; i++)
{
printf("%d.....%s", i, variables[i]);
printf("\n");
}
}