From 9d70c988533f0daa48b0a12ca0d3e40f09bd0f98 Mon Sep 17 00:00:00 2001 From: Mikkel Thestrup Date: Thu, 4 Dec 2025 09:56:07 +0100 Subject: A few bug fixes in graph.c --- src/graph.c | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/src/graph.c b/src/graph.c index f3e7517..cd2d796 100644 --- a/src/graph.c +++ b/src/graph.c @@ -18,8 +18,8 @@ Graph *graph_new(int n) { return NULL; } - graph->num_edges = n; - graph->num_vertices = 0; + graph->num_edges = 0; + graph->num_vertices = n; for (int i = 0; i < n; i++) { graph->vertices[i].id = i; @@ -57,6 +57,9 @@ void graph_remove_edge(Graph *g, int i, int j) { Graph *graph_read(const char *filename) { FILE *file = fopen(filename, "r"); + if (!file) + return NULL; + char line[1024]; fgets(line, 1024, file); @@ -66,7 +69,7 @@ Graph *graph_read(const char *filename) { Graph *g = graph_new(n); char c = line[0]; - int i, j = 0; + int i = 0, j = 0; while (fgets(line, 1024, file)) { while (c != '\n') { if (c == '1') { -- cgit v1.2.3-70-g09d2