-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.c
74 lines (59 loc) · 1.97 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
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include "input.h"
#include "array.h"
#include "my-string.h"
#include "line-functions.h"
#include "my-double.h"
/* Program that reads lines of words form input file
and output the numbers of similar lines */
int main() {
int numberOfLines = 0;
array lines = newArray(sizeof(line));
array words = newArray(sizeof(array));
array output = newArray(sizeof(array));
array inputLine = newArray(sizeof(char));
while(readString(&inputLine) > 0) {
splitLineBySpaces(&words, inputLine);
numberOfLines++;
switch (words.typeOfLine) {
case 0: { //correct line
line thisLine = separateNumbersFromWords(words);
thisLine.lineNumber = numberOfLines;
lowerCapitalisation(thisLine.words);
sortWords(&(thisLine.words));
sortNumbers(&(thisLine.numbers));
addOneMemorySpace(&lines);
lines.T.lines[lines.size - 1] = thisLine;
break;
}
case 1: //comment/empty line - nothing to do
break;
case 2: //incorrect line
fprintf(stderr, "ERROR %d\n",numberOfLines);
break;
}
clearWords(&words);
}
sortLines(&lines);
int i = 0;
while ( i < lines.size) {
addOneMemorySpace(&output);
output.T.matrix[output.size - 1] = findSimilarLines(&i, lines);
sortIntegers(&(output.T.matrix[output.size - 1]));
}
sortRows(&output);
for (int i = 0; i < output.size; i++) {
printf("%d",output.T.matrix[i].T.integers[0]);
for (int j = 1; j < output.T.matrix[i].size; j++) {
printf(" %d",output.T.matrix[i].T.integers[j]);
}
printf("\n");
}
killArray(&inputLine);
killMatrix(&output);
killLineArray(&lines);
killMatrix(&words);
exit(0);
}