diff --git a/cv8/program.c b/cv8/program.c index c52097e..9b14fab 100644 --- a/cv8/program.c +++ b/cv8/program.c @@ -10,7 +10,8 @@ struct tree { }; -struct tree* read_tree(){ +struct tree* read_tree(int* counter){ + int* c = counter; char buffer[50]; memset(buffer,0,50); char* r = fgets(buffer,50,stdin); @@ -25,6 +26,8 @@ struct tree* read_tree(){ if(buffer[0] != '\0'){ struct tree* node = calloc(1,sizeof(struct tree)); memcpy(node->value, buffer,50); + *c += 1; + counter = &c; if(buffer[0] != '*'){ if(node->left == NULL){ node->left = read_tree(); @@ -33,6 +36,20 @@ struct tree* read_tree(){ node->right = read_tree(); } } + if(node->left != NULL && node->right != NULL){ + *c -= 2; + counter = &c; + } + if(c == 1){ + r = fgets(buffer,50, stdin); + //int x = strlen(buffer); + // buffer[x-1]='\0'; + if(buffer[0] != '\n'){ + printf("Chybna databaza\n"); + exit(0); + } + } + return node; } @@ -139,8 +156,8 @@ int main(){ printf("Expert z bufetu to vie.\n"); struct tree* tree = NULL; - - tree = read_tree(); + int counter; + tree = read_tree(&counter); int count = count_leaves(tree); printf("Pozna %d druhov ovocia a zeleniny.\n", count);