Initializacia

This commit is contained in:
Kozar 2024-11-12 12:20:05 +00:00
parent 72e5b20347
commit 2b3c70feac

View File

@ -29,15 +29,18 @@ struct tree* read_tree() {
struct tree* load_tree() { struct tree* load_tree() {
struct tree* node = read_tree(); struct tree* node = read_tree();
if (!node) { if (!node) {
error_flag = 1;
return NULL; return NULL;
} }
if (node->value[0] != '*') { if (node->value[0] != '*') {
node->left = load_tree(); node->left = load_tree();
if (error_flag) return node;
node->right = load_tree(); node->right = load_tree();
} }
return node; return node;
} }
void run_tree(struct tree* tree) { void run_tree(struct tree* tree) {
if (!tree) { if (!tree) {
return; return;
@ -55,11 +58,7 @@ void run_tree(struct tree* tree) {
printf("Koniec vstupu\n"); printf("Koniec vstupu\n");
return; return;
}else if (response != 'a' && response != 'n') { }else if (response != 'a' && response != 'n') {
if (feof(stdin)) { printf("Nerozumiem\n");
printf("Chybna databaza\n");
} else {
printf("Nerozumiem\n");
}
return; return;
} }
@ -95,8 +94,9 @@ void count_items(struct tree* tree, int* count) {
int main() { int main() {
struct tree* root = load_tree(); struct tree* root = load_tree();
printf("Expert z bufetu to vie.\n"); printf("Expert z bufetu to vie.\n");
if (!root) { if (!root || error_flag) {
printf("Chybna databaza\n"); printf("Chybna databaza\n");
destroy_tree(root);
return 0; return 0;
} }
@ -106,7 +106,7 @@ int main() {
printf("Odpovedajte 'a' pre prvu moznost alebo 'n' pre druhu moznost.\n"); printf("Odpovedajte 'a' pre prvu moznost alebo 'n' pre druhu moznost.\n");
run_tree(root); run_tree(root);
destroy_tree(root); destroy_tree(root);
return 0; return 0;
} }