From 5a85ff58001551ecbdac4c96d79c5503d710a75a Mon Sep 17 00:00:00 2001 From: ov075wu Date: Thu, 20 Nov 2025 17:06:36 +0100 Subject: [PATCH] refresh --- du6/program.c | 19 +++++++++++++++---- 1 file changed, 15 insertions(+), 4 deletions(-) diff --git a/du6/program.c b/du6/program.c index a91f2de..01498f3 100644 --- a/du6/program.c +++ b/du6/program.c @@ -13,9 +13,8 @@ typedef struct TreeNode { static TreeNode* read_tree_node() { char buffer[MAXLINE]; - if (!fgets(buffer, sizeof(buffer), stdin)) { + if (!fgets(buffer, sizeof(buffer), stdin)) return NULL; - } if (buffer[0] == '\n' || buffer[0] == '\r') return NULL; @@ -54,9 +53,9 @@ static int count_leafs(TreeNode *root) { static int validate_tree(TreeNode *root) { if (!root) return 0; - int is_answer = (root->text[0] == '*'); + int is_leaf = (root->text[0] == '*'); - if (is_answer) { + if (is_leaf) { if (root->yes_branch || root->no_branch) return 0; return 1; @@ -104,6 +103,18 @@ int main() { return 0; } + char chk[MAXLINE]; + if (!fgets(chk, sizeof(chk), stdin)) { + printf("Chybna databaza\n"); + free_tree(root); + return 0; + } + if (!(chk[0] == '\n' || chk[0] == '\r')) { + printf("Chybna databaza\n"); + free_tree(root); + return 0; + } + int total = count_leafs(root); printf("Pozna %d druhov ovocia a zeleniny.\n", total);