From c8444fa97d7285af959d2efdc5b6e56be64dd9f9 Mon Sep 17 00:00:00 2001 From: Matus Tokarcik Date: Thu, 21 Mar 2024 22:58:36 +0100 Subject: [PATCH] cv5 --- cv5/program.c | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/cv5/program.c b/cv5/program.c index 349ef5b..0af2e1f 100644 --- a/cv5/program.c +++ b/cv5/program.c @@ -1,7 +1,7 @@ #include #include #include - +#include #define SIZE 100 struct student { @@ -67,13 +67,16 @@ int main() { char line[SIZE]; int votes; // Premenná pre počet hlasov char name[SIZE]; // Pole pre meno + bool chyba = false; // Načítanie a kontrola formátu vstupu while (1) { char* r = fgets(line,SIZE,stdin); if (r == NULL){ - break; + printf("Nepodarilo nacitat nic\n"); + chyba = true; + break; } if(line[0] == '\n'){ @@ -105,12 +108,13 @@ int main() { // Triedenie študentov pomocou qsort qsort(databaza, size, sizeof(struct student), compare_students); - + + if (chyba == false){ // Výpis výsledkov printf("Výsledky:\n"); for (int i = 0; i < size; i++) { printf("%d %s\n", databaza[i].votes, databaza[i].name); } - + } return 0; } \ No newline at end of file