From 192ea219b45f42ab69f4697066b21ce1814f667a Mon Sep 17 00:00:00 2001 From: Kozar Date: Tue, 12 Nov 2024 19:19:17 +0000 Subject: [PATCH] Initializacia --- cv7/program.c | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/cv7/program.c b/cv7/program.c index 0d71563..7d216e0 100644 --- a/cv7/program.c +++ b/cv7/program.c @@ -33,7 +33,6 @@ struct tree* load_tree() { node->right = load_tree(); } else if (node->left != NULL || node->right != NULL) { printf("Expert z bufetu to vie.\n"); - printf("Chybna databaza\n"); free(node); return NULL; } @@ -89,12 +88,22 @@ void count_items(struct tree* tree, int* count) { int main() { struct tree* root = load_tree(); + if (!root) { + printf("Chybna databaza\n"); return 0; } printf("Expert z bufetu to vie.\n"); + // Check if the input is empty after loading the tree + char buffer[SIZE]; + if (fgets(buffer, SIZE, stdin) == NULL || buffer[0] == '\n') { + printf("Chybna databaza\n"); + destroy_tree(root); + return 0; + } + int count = 0; count_items(root, &count); printf("Pozna %d druhov ovocia a zeleniny.\n", count);