Initializacia
This commit is contained in:
parent
fe7326837f
commit
0e5b2261b0
@ -12,7 +12,9 @@ struct tree {
|
||||
|
||||
struct tree* read_tree() {
|
||||
char buffer[SIZE];
|
||||
if (fgets(buffer, SIZE, stdin) == NULL || buffer[0] == '\n') {
|
||||
memset(buffer, 0, SIZE);
|
||||
char* r = fgets(buffer, SIZE, stdin);
|
||||
if (!r || buffer[0] == '\n') {
|
||||
return NULL;
|
||||
}
|
||||
buffer[strcspn(buffer, "\n")] = 0;
|
||||
@ -38,22 +40,21 @@ void run_tree(struct tree* tree) {
|
||||
return;
|
||||
}
|
||||
|
||||
printf("%s\n", tree->value);
|
||||
|
||||
if (tree->value[0] == '*') {
|
||||
printf("Koniec\n");
|
||||
// If it's an answer
|
||||
printf("*%s\nKoniec\n", tree->value + 1);
|
||||
return;
|
||||
}
|
||||
|
||||
printf("Odpovedajte 'a' pre prvu moznost alebo 'n' pre druhu moznost.\n");
|
||||
printf("%s\n", tree->value);
|
||||
|
||||
char response;
|
||||
while (1) {
|
||||
if (scanf(" %c", &response) != 1 || (response != 'a' && response != 'n')) {
|
||||
printf("Nerozumiem\n");
|
||||
continue;
|
||||
}
|
||||
break;
|
||||
if (scanf(" %c", &response) != 1) {
|
||||
printf("Koniec vstupu\n");
|
||||
return;
|
||||
} else if (response != 'a' && response != 'n') {
|
||||
printf("Nerozumiem\n");
|
||||
return;
|
||||
}
|
||||
|
||||
if (response == 'a') {
|
||||
@ -83,9 +84,8 @@ void count_items(struct tree* tree, int* count) {
|
||||
}
|
||||
|
||||
int main() {
|
||||
printf("Expert z bufetu to vie.\n");
|
||||
|
||||
struct tree* root = load_tree();
|
||||
printf("Expert z bufetu to vie.\n");
|
||||
if (!root) {
|
||||
printf("Chybna databaza\n");
|
||||
return 0;
|
||||
@ -94,8 +94,10 @@ int main() {
|
||||
int count = 0;
|
||||
count_items(root, &count);
|
||||
printf("Pozna %d druhov ovocia a zeleniny.\n", count);
|
||||
printf("Odpovedajte 'a' pre prvu moznost alebo 'n' pre druhu moznost.\n");
|
||||
|
||||
run_tree(root);
|
||||
|
||||
destroy_tree(root);
|
||||
return 0;
|
||||
}
|
Loading…
Reference in New Issue
Block a user