-
Notifications
You must be signed in to change notification settings - Fork 0
/
Source.cpp
70 lines (53 loc) · 1.51 KB
/
Source.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
#include "Header.h"
#include <cstdio>
int main()
{
int amountOfVariable;
int numberOfOperation = 0;
int maxNumberOfOperation = getLinesOfOperations();
char** variables = getVaraibles(&amountOfVariable);
char* fullArray = (char*)malloc(sizeof(char) * 1);
int initalizedVariable = amountOfVariable;
cin.get();
//buffer array (get data form each line)
char* kola = (char*)malloc(sizeof(char) * 1000);
int fullSize = 0;
int fullLine = 0;
int h = 1 / 2;
while (!cin.eof())
{
cin.getline(kola, 1000);
while (kola[fullLine++] != '\0');
kola[fullLine - 1] = ' ';
kola[fullLine] = '\0';
fullArray = (char*)realloc(fullArray, fullSize + fullLine);
for (int i = 0; i < fullLine; i++)
{
fullArray[fullSize + i] = kola[i];
}
fullSize += fullLine;
fullLine = 0;
}
//secured against memory leak
fullArray = (char*)realloc(fullArray, fullSize + 2);
fullArray[fullSize] = '\0';
//free buffer line
free(kola);
//initalize first variable using second line of code
VarVector* variablesContainer = charToVar(variables, amountOfVariable);
int i = 0;
int shift;
//main loop
condition(fullArray, i, fullSize, &numberOfOperation, maxNumberOfOperation, variablesContainer, &shift);
//secured against additional counting (leaving from loops)
if (numberOfOperation > maxNumberOfOperation)
{
numberOfOperation = maxNumberOfOperation;
}
//show result on terminal
showResult(variablesContainer, numberOfOperation);
//free memory
free(variables);
delete variablesContainer;
free(fullArray);
}