From 00f8a744366614aa0b8c3182e090ae94fc0a73b3 Mon Sep 17 00:00:00 2001 From: Bohdan Kapliuk Date: Mon, 11 Nov 2024 19:05:13 +0200 Subject: [PATCH] cv7 --- cv7/program.c | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/cv7/program.c b/cv7/program.c index da58af4..0cd8271 100644 --- a/cv7/program.c +++ b/cv7/program.c @@ -15,11 +15,18 @@ struct tree* read_tree(int* counter) { memset(buffer, 0, SIZE); char* r = fgets(buffer, SIZE, stdin); if (buffer[0] == '\n') { - printf("Chybna databaza\n"); - return 0; + return NULL; } struct tree* tree = calloc(1, sizeof(struct tree)); + if(tree == NULL){ + printf("Chybna databaza\n"); + exit(0); + } tree->value = malloc(strlen(buffer) + 1); + if(tree->value == NULL){ + printf("Chybna databaza\n"); + exit(0); + } strcpy(tree->value, buffer); if (buffer[0] == '*') { (*counter)++; @@ -63,6 +70,7 @@ int main() { int counter = 0; struct tree* root = read_tree(&counter); printf("Expert z bufetu to vie.\n"); + printf("Pozna %d druhov ovocia a zeleniny.\n", counter); printf("Odpovedajte 'a' pre prvu moznost alebo 'n' pre druhu moznost.\n"); print_tree(root);