Aktualizovat du5/program.c
This commit is contained in:
parent
651815e5a5
commit
e96d69f52e
@ -1,16 +1,19 @@
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <stdbool.h>
|
||||
|
||||
#define SIZE 128
|
||||
|
||||
int main()
|
||||
{
|
||||
char line[SIZE];
|
||||
char answer[SIZE];
|
||||
char secondAnswer[SIZE];
|
||||
int readAnswerIndex = 0;
|
||||
|
||||
answer[0] = '\0';
|
||||
char option1[SIZE];
|
||||
char option2[SIZE];
|
||||
bool isFirstOptionLoaded = false;
|
||||
char answer = '';
|
||||
|
||||
option1[0] = '\0';
|
||||
option2[0] = '\0';
|
||||
line[0] = '\0';
|
||||
|
||||
while (fgets(line, SIZE, stdin) != NULL)
|
||||
@ -18,18 +21,17 @@ int main()
|
||||
if (line[0] == '*')
|
||||
{
|
||||
//precita a ulozi odpoved na zaklade kontrolnej premeny
|
||||
//ak sa precital prvy rok, inkrementuje sa kontrolna premena
|
||||
if (readAnswerIndex == 0)
|
||||
if (!isFirstOptionLoaded)
|
||||
{
|
||||
sscanf(line, "%s [^\n]", &answer);
|
||||
readAnswerIndex += 1;
|
||||
sscanf(line, "%s [^\n]", &option1);
|
||||
isFirstOptionLoaded = true;
|
||||
}
|
||||
else
|
||||
{
|
||||
sscanf(line, "%s [^\n]", &secondAnswer);
|
||||
sscanf(line, "%s [^\n]", &option2);
|
||||
}
|
||||
}
|
||||
else if (line[0] == 'n')
|
||||
else if (line[0] == 'n' && line[1] == '\n')
|
||||
{
|
||||
break;
|
||||
}
|
||||
@ -39,7 +41,14 @@ int main()
|
||||
printf("Pozna 2 druhov ovocia a zeleniny.\n");
|
||||
printf("Odpovedajte 'a' pre prvu moznost alebo 'n' pre druhu moznost.\n");
|
||||
printf("Je to ovocie alebo zelenina\n");
|
||||
printf("%s\n", answer);
|
||||
if (answer = 'n')
|
||||
{
|
||||
printf("%s\n", option1);
|
||||
}
|
||||
else
|
||||
{
|
||||
printf("%s\n", option2);
|
||||
}
|
||||
printf("Koniec\n");
|
||||
|
||||
return 0;
|
||||
|
||||
Loading…
Reference in New Issue
Block a user