From f256260acafe10b79dcbfabb906c6a76db50be1c Mon Sep 17 00:00:00 2001 From: Kozar Date: Sun, 10 Nov 2024 16:12:30 +0000 Subject: [PATCH] Initializacia --- cv7/program.c | 20 ++++++++------------ 1 file changed, 8 insertions(+), 12 deletions(-) diff --git a/cv7/program.c b/cv7/program.c index 6261790..1394895 100644 --- a/cv7/program.c +++ b/cv7/program.c @@ -21,10 +21,6 @@ struct tree* read_tree() { } buffer[strcspn(buffer, "\n")] = 0; - if (buffer[0] == '*' && buffer[1] == ' ') { - error_flag = 1; // Invalid format if there's a space after '*' - } - struct tree* node = calloc(1, sizeof(struct tree)); strncpy(node->value, buffer, SIZE - 1); return node; @@ -35,7 +31,7 @@ struct tree* load_tree() { if (!node) { return NULL; } - if (error_flag || node->value[0] != '*') { + if (node->value[0] != '*') { node->left = load_tree(); node->right = load_tree(); } @@ -55,11 +51,8 @@ void run_tree(struct tree* tree) { printf("%s\n", tree->value); char response; - if (scanf(" %c", &response) != 1) { - printf("Koniec vstupu\n"); - return; - } else if (response != 'a' && response != 'n') { - printf("Nerozumiem\n"); + if (scanf(" %c", &response) != 1 || (response != 'a' && response != 'n')) { + error_flag = 1; return; } @@ -94,9 +87,8 @@ void count_items(struct tree* tree, int* count) { int main() { struct tree* root = load_tree(); printf("Expert z bufetu to vie.\n"); - if (!root || error_flag) { + if (!root) { printf("Chybna databaza\n"); - destroy_tree(root); return 0; } @@ -107,6 +99,10 @@ int main() { run_tree(root); + if (error_flag) { + printf("Chybna databaza\n"); + } + destroy_tree(root); return 0; }