Initializacia

This commit is contained in:
Kozar 2024-11-12 19:19:17 +00:00
parent e548847f2e
commit 192ea219b4

View File

@ -33,7 +33,6 @@ struct tree* load_tree() {
node->right = load_tree();
} else if (node->left != NULL || node->right != NULL) {
printf("Expert z bufetu to vie.\n");
printf("Chybna databaza\n");
free(node);
return NULL;
}
@ -89,12 +88,22 @@ void count_items(struct tree* tree, int* count) {
int main() {
struct tree* root = load_tree();
if (!root) {
printf("Chybna databaza\n");
return 0;
}
printf("Expert z bufetu to vie.\n");
// Check if the input is empty after loading the tree
char buffer[SIZE];
if (fgets(buffer, SIZE, stdin) == NULL || buffer[0] == '\n') {
printf("Chybna databaza\n");
destroy_tree(root);
return 0;
}
int count = 0;
count_items(root, &count);
printf("Pozna %d druhov ovocia a zeleniny.\n", count);