From ef5fd0117684825a0aa5a089ad42569bd6415b8f Mon Sep 17 00:00:00 2001 From: Ivan Leichenko Date: Fri, 15 Nov 2024 07:07:10 +0100 Subject: [PATCH] cv7 --- cv7/program.c | 27 ++++++++++++++++++--------- 1 file changed, 18 insertions(+), 9 deletions(-) diff --git a/cv7/program.c b/cv7/program.c index 54fe039..8b95c56 100644 --- a/cv7/program.c +++ b/cv7/program.c @@ -73,7 +73,7 @@ int count_non_leaf_nodes(struct tree *node) return 1 + count_non_leaf_nodes(node->left) + count_non_leaf_nodes(node->right); } -void interact(struct tree *node) +void interact(struct tree *node, int fstenter) { if (node == NULL) { @@ -92,7 +92,6 @@ void interact(struct tree *node) char answer[SIZE]; while (1) { - if (fgets(answer, sizeof(answer), stdin) == NULL) { printf("Koniec vstupu\n"); @@ -101,24 +100,33 @@ void interact(struct tree *node) size_t len = strlen(answer); - if (answer[len - 1] == '\n') { + if (answer[len - 1] == '\n') + { answer[len - 1] = '\0'; } if (strlen(answer) != 1 || (answer[0] != 'a' && answer[0] != 'n')) { - printf("Nerozumiem\n"); - break; + if(fstenter == 0) + { + fstenter = 1; + continue; + } + else + { + printf("Nerozumiem\n"); + return; + } } if (answer[0] == 'a') { - interact(node->left); + interact(node->left, fstenter); return; } else if (answer[0] == 'n') { - interact(node->right); + interact(node->right, fstenter); return; } @@ -128,6 +136,7 @@ void interact(struct tree *node) int main() { struct tree *root = read_tree(); + //getchar(); int leafs = count_leaf_nodes(root); if(leafs == 0) { @@ -142,8 +151,8 @@ int main() printf("Chyba pri nacitani databazy pravidiel.\n"); return 1; } - - interact(root); + int fstenter = 0; + interact(root, fstenter); free_tree(root); return 0;