-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathFIrstPassDataCoding.c
60 lines (49 loc) · 1.72 KB
/
FIrstPassDataCoding.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
#include "declarationsHeader.h"
/*
* Codes the numbers and puts its memory words into the data list.
*/
void codeDataLine(int *DC) {
char lineCpy[LINE_SIZE];
linePtr ptr = lineListHead;
strcpy(lineCpy, line);
if (dataIsAnArray(lineCpy)) {
arrayCoding(ptr, lineCpy, DC);
} else {/*Its not an array,but one number, inserting it.*/
oneNumberCoding(ptr, DC);
}
}
void arrayCoding(linePtr ptr, char *lineCpy, int *DC) {
char temp[STRING_SIZE], *dataVar;
size_t i = 1, firstInt, label = 3, noLabel = 2;
/*Checking if there's a label before the data.*/
firstInt = strchr(lineCpy, ISLABEL) ? label : noLabel;
/*starting from the third string to avoid non numbers words.*/
for (ptr = lineListHead; ptr && i != firstInt; ptr = ptr->next, i++);
if (!(atoi(ptr->str)))
printError(order_error);
for (; ptr; ptr = ptr->next) {
/*Taking the ints and putting into the data list.*/
strcpy(temp, ptr->str);
dataVar = strtok(temp, COMMA_STR);
while (dataVar != NULL) {
if (strchr(dataVar, DOT) != NULL)
printErrorWithComment(float_err, dataVar);
else
addToDataList(atoi(dataVar), DC);
dataVar = strtok(NULL, COMMA_STR);
}
}
}
void oneNumberCoding(linePtr ptr, int *DC) {
/*Getting to the first number.*/
for (ptr = lineListHead; ptr && (!atoi(ptr->str)); ptr = ptr->next);
if (ptr == NULL)
printError(data_line_with_no_data);
else if (strchr(ptr->str, DOT))
printErrorWithComment(float_err, ptr->str);
else
addToDataList(atoi(ptr->str), DC);
}
boolean dataIsAnArray(char *lineCpy) {
return strchr(lineCpy, COMMA) != NULL;
}