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