funguje
This commit is contained in:
parent
ef8b2a3dd2
commit
066c3c4315
@ -2,6 +2,7 @@
|
|||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include <assert.h>
|
#include <assert.h>
|
||||||
|
#include <ctype.h>
|
||||||
|
|
||||||
#define SIZE 256
|
#define SIZE 256
|
||||||
|
|
||||||
@ -12,6 +13,16 @@ struct tree
|
|||||||
struct tree* right;
|
struct tree* right;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
void trim_whitespace(char* str)
|
||||||
|
{
|
||||||
|
int i=strlen(str)-1;
|
||||||
|
while (i>=0 && isspace(str[i]))
|
||||||
|
{
|
||||||
|
str[i]='\0';
|
||||||
|
i--;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
struct tree* read_tree()
|
struct tree* read_tree()
|
||||||
{
|
{
|
||||||
char buffer[SIZE];
|
char buffer[SIZE];
|
||||||
@ -23,6 +34,7 @@ struct tree* read_tree()
|
|||||||
{
|
{
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
trim_whitespace(buffer);
|
||||||
struct tree* node=(struct tree*)calloc(1, sizeof(struct tree));
|
struct tree* node=(struct tree*)calloc(1, sizeof(struct tree));
|
||||||
strcpy(node->value, buffer);
|
strcpy(node->value, buffer);
|
||||||
if (buffer[0]!='*')
|
if (buffer[0]!='*')
|
||||||
@ -63,7 +75,14 @@ void run_knowledge_system(struct tree* node)
|
|||||||
{
|
{
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
printf("%s", node->value);
|
if (node->value[0]=='*')
|
||||||
|
{
|
||||||
|
printf("%s\n", node->value);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
printf("%s\n", node->value);
|
||||||
|
}
|
||||||
if (node->value[0]=='*')
|
if (node->value[0]=='*')
|
||||||
{
|
{
|
||||||
return;
|
return;
|
||||||
@ -111,9 +130,9 @@ int main()
|
|||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
int answer_count=count_answers(knowledge_base);
|
int answer_count=count_answers(knowledge_base);
|
||||||
printf("MUDrC to vie.\n");
|
printf("Expert_x_bufetu_to_vie.\n");
|
||||||
printf("Pozna %d druhov ovocia a zeleniny.\n",answer_count);
|
printf("Pozna_%d_druhov_ovocia_a_zeleniny.\n", answer_count);
|
||||||
printf("Odpovedajte 'a' alebo 'n'\n");
|
printf("Odpovedajte_'a'_pre_prvu_moznost_alebo_'n'_pre_druhu_moznost.\n");
|
||||||
run_knowledge_system(knowledge_base);
|
run_knowledge_system(knowledge_base);
|
||||||
destroy_tree(knowledge_base);
|
destroy_tree(knowledge_base);
|
||||||
return 0;
|
return 0;
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user