aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/graph.c9
1 files 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') {