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