From a83442497606177dbcad9303032dbbb0f07414f7 Mon Sep 17 00:00:00 2001 From: Viktor Daniv Date: Fri, 15 Nov 2024 01:08:27 +0000 Subject: [PATCH] Update cv7/program.c --- cv7/program.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/cv7/program.c b/cv7/program.c index 69e94ce..b45f611 100644 --- a/cv7/program.c +++ b/cv7/program.c @@ -81,7 +81,10 @@ struct tree* read_tree() { // Read a line from stdin char* r = fgets(buffer, SIZE, stdin); - assert(r); // Ensure reading was successful + if (r == NULL) { + fprintf(stderr, "Error: Failed to read input\n"); + exit(1); // Exit the program if reading fails + } // Allocate memory for a new tree node struct tree* node = calloc(1, sizeof(struct tree)); @@ -105,6 +108,7 @@ struct tree* read_tree() { return node; } + int main() { int counter = 0; struct tree *root = read_tree(&counter); // Try reading the tree