Update cv7/program.c

This commit is contained in:
Marat Izmailov 2024-11-13 21:19:19 +00:00
parent 6e022baaca
commit 04b91e7d5d

View File

@ -38,7 +38,6 @@ Node* parse_rules() {
int stack_top = -1; int stack_top = -1;
while (fgets(line, sizeof(line), stdin)) { while (fgets(line, sizeof(line), stdin)) {
// Trim newline
line[strcspn(line, "\n")] = 0; line[strcspn(line, "\n")] = 0;
if (strlen(line) == 0) break; if (strlen(line) == 0) break;
@ -72,19 +71,17 @@ Node* parse_rules() {
void ask_question(Node *node) { void ask_question(Node *node) {
if (!node) return; if (!node) return;
if (node->yes == NULL && node->no == NULL) { if (node->yes == NULL && node->no == NULL) {
printf("*%s\n", node->content);
printf("Koniec\n"); printf("Koniec\n");
return; return;
} }
printf("%s\n", node->content); printf("%s\n", node->content);
if (node->yes && node->yes->content[0] != '*') {
printf("Odpovedajte 'a' pre prvu moznost alebo 'n' pre druhu moznost.\n");
}
char response; char response;
while (1) { while (1) {
response = getchar(); response = getchar();
getchar(); // To capture newline getchar(); // Capture newline
if (response == 'a' && node->yes) { if (response == 'a' && node->yes) {
ask_question(node->yes); ask_question(node->yes);
break; break;
@ -109,9 +106,9 @@ int main() {
int answer_count = count_answers(root); int answer_count = count_answers(root);
printf("Pozna %d druhov ovocia a zeleniny.\n", answer_count); printf("Pozna %d druhov ovocia a zeleniny.\n", answer_count);
printf("Odpovedajte 'a' pre prvu moznost alebo 'n' pre druhu moznost.\n");
if (root) { if (root) {
printf("Odpovedajte 'a' pre prvu moznost alebo 'n' pre druhu moznost.\n");
ask_question(root); ask_question(root);
} }