This commit is contained in:
Jana Kapalková 2026-04-16 13:46:02 +02:00
parent 3439976ef7
commit f30049329c

View File

@ -25,10 +25,12 @@ struct Node* read_tree(void) {
}
struct Node* node = calloc(1, sizeof(struct Node));
if (node == NULL) return NULL;
memcpy(node->value, buffer, SIZE);
strcpy(node->value, buffer);
if (buffer[0] != '*') {
node->left = read_tree();
node->right = read_tree();
if (node->left == NULL || node->right == NULL) {
destroy_tree(node);
return NULL;
@ -48,7 +50,7 @@ void run_system(struct Node* node) {
printf("%s", node->value);
if (node->left == NULL && node->right == NULL) {
printf("End\n");
printf("Koniec\n");
return;
}
char answer[SIZE];
@ -71,18 +73,15 @@ int main(void) {
return 1;
}
char sep[SIZE];
if (fgets(sep, SIZE, stdin) == NULL || (sep[0] != '\n' && sep[0] != '\r')) {
printf("Error: missing blank separator line.\n");
destroy_tree(root);
return 1;
}
fgets(sep, SIZE, stdin);
int leaves = count_leaves(root);
printf("Expert z bufetu to vie.\n");
printf("Pozna %d druhov ovocia a zeleniny.\n", leaves);
printf("Odpovedajte 'a' pre prvu moznost alebo 'n' pre druhu moznost.\n");
run_system(root);
destroy_tree(root);
destroy_tree(root);
return 0;
}