aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/graph.c27
1 files changed, 26 insertions, 1 deletions
diff --git a/src/graph.c b/src/graph.c
index cf45e2b..5f4b5d6 100644
--- a/src/graph.c
+++ b/src/graph.c
@@ -1,5 +1,7 @@
#include "graph.h"
#include "linked_list.h"
+#include <assert.h>
+#include <stdio.h>
#include <stdlib.h>
// Need to declare 'graph_delete' for use in 'graph_new'
@@ -42,7 +44,30 @@ void graph_add_edge(Graph *g, int i, int j) {
}
Graph *graph_read(const char *filename) {
- Graph *g = graph_new(69);
+ FILE *file = fopen(filename, "r");
+ char line[1024];
+ fgets(line, 1024, file);
+
+ int n = atoi(line);
+ if (!n)
+ return NULL;
+ Graph *g = graph_new(n);
+
+ char c = line[0];
+ int i, j = 0;
+ while (fgets(line, 1024, file)) {
+ while (c != '\n') {
+ if (c == '1') {
+ graph_add_edge(g, i, j);
+ j++;
+ } else if (c == '0') {
+ j++;
+ }
+ c++;
+ }
+ i++;
+ }
+
return g;
}