This commit is contained in:
Deinerovych 2024-11-06 10:00:29 +01:00
parent 79c9d86bea
commit b19a7bfeac

View File

@ -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);