#include #include #include #include #include #define SIZE 200 struct tree { char value[SIZE]; struct tree *left, *right; }; 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; } 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){ print_tree(tree->left,offset +3); } if (tree->right){ print_tree(tree->right,offset +3); } } int main(void) { struct tree *tr; tr=read_tree(); printf("Expert z bufetu to vie.\n"); printf("Pozna 2 druhov ovocia a zeleniny.\n"); struct tree *p=tr; do { printf("%s",p->value); 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; }while(1); printf("Koniec"); return 0; }