diff --git a/cv7/program.c b/cv7/program.c index bfc9c86..eaa3f7e 100644 --- a/cv7/program.c +++ b/cv7/program.c @@ -50,11 +50,11 @@ int count_products(Node *node) { void run_expert_system(Node *node) { while (node) { if (!node->yes && !node->no) { - printf("The expert knows: %s.\n", node->text); + printf("Expert z bufetu to vie: %s.\n", node->text); return; } printf("%s\n", node->text); - printf("Answer 'a' for the first option or 'n' for the second option: "); + printf("Odpovedajte 'a' pre prvu moznost alebo 'n' pre druhu moznost: "); char answer; scanf(" %c", &answer); if (answer == 'a') { @@ -62,12 +62,20 @@ void run_expert_system(Node *node) { } else if (answer == 'n') { node = node->no; } else { - printf("Invalid answer. Exiting.\n"); + printf("Neplatná odpoveď. Koniec.\n"); return; } } } +void free_tree(Node *node) { + if (node) { + free_tree(node->yes); + free_tree(node->no); + free(node); + } +} + void create_default_knowledge_base() { FILE *file = fopen("knowledge_base.txt", "w"); if (!file) { @@ -78,13 +86,11 @@ void create_default_knowledge_base() { fprintf(file, "*Jablko\n"); fprintf(file, "*Mrkva\n"); fclose(file); - printf("Default knowledge base file 'knowledge_base.txt' has been created.\n"); } int main() { FILE *file = fopen("knowledge_base.txt", "r"); if (!file) { - printf("Knowledge base file not found. Creating default file.\n"); create_default_knowledge_base(); file = fopen("knowledge_base.txt", "r"); if (!file) { @@ -97,16 +103,16 @@ int main() { fclose(file); if (!root) { - printf("The knowledge base could not be loaded.\n"); + printf("Báza znalostí sa nedá načítať.\n"); return 1; } int product_count = count_products(root); - printf("The system knows about %d types of fruits and vegetables.\n", product_count); + printf("Pozna %d druhov ovocia a zeleniny.\n", product_count); run_expert_system(root); - free(root); + free_tree(root); return 0; }