-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdataCollection.c
81 lines (71 loc) · 1.71 KB
/
dataCollection.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
#include "dataCollection.h"
#include "dataStructure.h"
#include "fileHandler.h"
#include "binaryConvertor.h"
#include "utils.h"
/* dc counter */
static int dc = 0;
/* data collection */
int dataCollection[1000];
int addStringData(char* data)
{
int i = 0, currentDc = dc, length = strlen(data);
for(i = 0; i < length;i++)
{
dataCollection[dc] = data[i];
dc++;
}
/* add the indicator for the end of the string */
dataCollection[dc] = '\0';
dc++;
/* return the dc of the beginning of the string */
return currentDc;
}
int addNumbersData(int* dataArray, int arrayLength)
{
int i = 0, currentDc = dc;
for(i = 0;i< arrayLength; i++)
{
dataCollection[dc] = dataArray[i];
dc++;
}
/* return the dc of the first number */
return currentDc;
}
int getDataByID(int dcRefrenceID)
{
return dataCollection[dcRefrenceID];
}
void clearData()
{
int i = 0;
for(i = 0;i < dc; i++)
{
/* set all the values to zero */
dataCollection[i] = 0;
}
dc = 0;
}
int getDCPointer()
{
return dc;
}
void printDataCollection(int icRefrence)
{
int i = 0, lineRefrence;
char *lineNumber, *dataOutput;
WordDef * base8;
for(i = 0;i < dc; i++)
{
lineRefrence = i + icRefrence;
/* convert the data and line numbers to special base 8*/
lineNumber = getSpecialBase8String(lineRefrence);
base8 = convertDecimalNumberToBase8Word(dataCollection[i]);
dataOutput = getStringFromBase8Word(base8);
/* print to the ob file*/
objWriteToFile("%s %s\n", lineNumber, dataOutput);
free(lineNumber);
free(base8);
free(dataOutput);
}
}