From 6d8fbb2e83823b7b14d3158ef91912997ad7759b Mon Sep 17 00:00:00 2001 From: Yurii Yakovenko Date: Mon, 11 Nov 2024 21:56:32 +0000 Subject: [PATCH] Update cv7/program.c --- cv7/program.c | 41 ++++++++++++++++++++--------------------- 1 file changed, 20 insertions(+), 21 deletions(-) diff --git a/cv7/program.c b/cv7/program.c index 26d32b8..2cb365c 100644 --- a/cv7/program.c +++ b/cv7/program.c @@ -4,14 +4,13 @@ #include #include - #define SIZE 200 struct tree { - + char value[SIZE]; - + struct tree *left, *right; }; @@ -21,22 +20,22 @@ struct tree* read_tree() char buffer[SIZE]; memset(buffer,0,SIZE); char* r = fgets(buffer,SIZE,stdin); - + assert(r); struct tree* node = (struct tree*)calloc(1,sizeof(struct tree)); memcpy(node->value,buffer,SIZE); - - - + + + node->left=NULL; node->right=NULL; if(node->value[0]!='*') { - + node->left=read_tree(node->left); - + node->right=read_tree(node->right); } return node; @@ -47,7 +46,7 @@ void print_tree(struct tree* tree,int offset){ for (int i = 0; i < offset; i++){ printf("."); } - + if(tree) printf("%s",tree->value); if (tree->left){ @@ -65,6 +64,7 @@ int main(void) struct tree *tr; tr=read_tree(); + char t; printf("Expert z bufetu to vie.\n"); printf("Pozna 2 druhov ovocia a zeleniny.\n"); @@ -76,22 +76,21 @@ int main(void) if(p->value[0]=='*') break; printf("Odpovedajte 'a' pre prvu moznost alebo 'n' pre druhu moznost.\n"); - char t=fgetc(stdin); - if(t=='a') - p=p->left; - if(t=='n') - p=p->right; + do + { + t=fgetc(stdin); + if(t=='a') + {p=p->left; break;} + if(t=='n') + {p=p->right; break;} + }while(1); }while(1); + printf("Koniec\n"); + - - - - printf("Koniec"); - - return 0; }