-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.c
64 lines (53 loc) · 1.35 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
#include "graph.h"
#include "graph_functions.h"
#include <stdbool.h>
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
void
print_usage() {
printf("usage: ex1 [-p] graph\n -p: print graph structure\n graph: file containing the graph data\n");
}
int
main(int argc, char* argv[]) {
if (argc < 2) {
print_usage();
exit(EXIT_FAILURE);
}
int pflag = false;
int c;
while ((c = getopt (argc, argv, "ph:")) != -1) {
switch (c) {
case 'p':
pflag = true;
break;
case 'h':
print_usage();
exit(EXIT_SUCCESS);
break;
default:
print_usage();
exit(EXIT_FAILURE);
}
}
// assume file name is always last argument
FILE *fp = fopen(argv[argc-1], "r");
if (fp == NULL) {
perror("Error when opening file");
exit(EXIT_FAILURE);
}
Graph g = graph_read(fp);
fclose(fp);
if (pflag) {
graph_pretty_print(g);
}
StronglyConnected_p areas = get_strongly_connected(&g);
for (int i = 0; i <= areas->size; ++i) {
for (int j = 0; j < areas->areas[i]->size; ++j) {
printf("%d ", vector_get(areas->areas[i], j));
}
printf("\n");
}
graph_destroy(g);
return EXIT_SUCCESS;
}