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