From cfb3f31df345ea2d5dfa28496debe0fb85168e12 Mon Sep 17 00:00:00 2001 From: Maryna Kravtsova Date: Sun, 22 Nov 2020 15:59:48 +0100 Subject: [PATCH] buffet --- cv8/program.c | 39 +++++++++++++++++++++++++++------------ 1 file changed, 27 insertions(+), 12 deletions(-) diff --git a/cv8/program.c b/cv8/program.c index ca76ed9..6fa8953 100644 --- a/cv8/program.c +++ b/cv8/program.c @@ -34,20 +34,35 @@ struct tree* read_tree(){ } } -struct tree* search(struct tree* this){ - - int c = getchar(); - if(this == NULL || this->value[0] == '*'){ - return this; - } +void search(struct tree* this){ - if(c == 'a'){ + char buffer[5]; + memset(buffer,0,5); + char* r = fgets(buffer,5,stdin); + int x = strlen(buffer); + buffer[x-1]='\0'; + + if(this == NULL){ + return; + } + if(buffer[0] == 'a'){ + if(this->left->value[0] == '*'){ + printf("%s\n", this->left->value); + return; + } printf("%s\n", this->left->value); - return search(this->left); + search(this->left); + } - else if(c == 'n'){ + + else if(buffer[0] == 'n'){ + if(this->right->value[0] == '*'){ + printf("%s\n", this->right->value); + return; + } printf("%s\n", this->right->value); - return search(this->right); + search(this->right); + } } @@ -140,8 +155,8 @@ int main(){ printf("Expert z bufetu to vie.\n"); printf("Pozna %d druhov ovocia a zeleniny.\n", count); printf("Odpovedajte 'a' pre prvu moznost alebo 'n' pre druhu moznost.\n"); - printf("%s\n", tree->value); - tree = search(tree); + //printf("%s\n", tree->value); + search(tree); destroy_tree(tree); printf("Koniec\n"); return 0;