diff --git a/cv7/program.c b/cv7/program.c index 89ca066..bfc9c86 100644 --- a/cv7/program.c +++ b/cv7/program.c @@ -68,14 +68,30 @@ void run_expert_system(Node *node) { } } +void create_default_knowledge_base() { + FILE *file = fopen("knowledge_base.txt", "w"); + if (!file) { + perror("Failed to create the knowledge base file"); + exit(1); + } + fprintf(file, "Je to ovocie alebo zelenina?\n"); + fprintf(file, "*Jablko\n"); + fprintf(file, "*Mrkva\n"); + fclose(file); + printf("Default knowledge base file 'knowledge_base.txt' has been created.\n"); +} + int main() { - printf("Attempting to open the knowledge base file...\n"); FILE *file = fopen("knowledge_base.txt", "r"); if (!file) { - perror("Failed to open the knowledge base file"); - return 1; + printf("Knowledge base file not found. Creating default file.\n"); + create_default_knowledge_base(); + file = fopen("knowledge_base.txt", "r"); + if (!file) { + perror("Failed to open the newly created knowledge base file"); + return 1; + } } - printf("File successfully opened.\n"); Node *root = parse_knowledge_base(file); fclose(file);