-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.c
52 lines (45 loc) · 1.38 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
#include <stdio.h>
#include <stdlib.h>
#include "divider.h"
#include <time.h>
/**
@file main.c
**Date:** 18.9.2020
* main.c Summary:
* This is the main file, reads the program input, runs the algorithms,
* and saves the output to the specified directory.
* if the specified path is incorrect or not found, an error will be given,
* if the input is corrupt or incorrect, and error will be given,
* if the input graph has zero edges, an error will be given
* if there is an unsuccessful memory allocation during the program run, an error will be given.
*/
/*Reads input, calculates groups, and saves to output */
int main(int argc, char **argv) {
networks *graphs = NULL;
division *div;
FILE *input;
FILE *output;
/*Checks if program arguments are OK */
srand(time(NULL));
if (argc != 3) {
error(ARGSERROR);
exit(EXIT_FAILURE);
}
/*Reads input */
input = fopen(argv[1], "rb");
output = fopen(argv[2], "wb");
graphs = readGraph(input);
/* Allocates group division struct, runs findGroup Algorithm */
div = allocateDivision(graphs->n);
div->findGroups(div, graphs);
/*Writes division to binary file */
div->writeDivision(div, output);
/*Frees all allocated data*/
graphs->free(graphs, div->numOfGroups);
div->free(div);
free(graphs);
free(div);
fclose(input);
fclose(output);
return 0;
}