From 25eb67de10baf0f6b623d6843f44a72b23e065ca Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tam=C3=A1=C5=A1?= Date: Thu, 21 Mar 2024 17:18:40 +0000 Subject: [PATCH] Update 'cv5/program.c' --- cv5/program.c | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/cv5/program.c b/cv5/program.c index 7aaaa58..ddf0ca1 100644 --- a/cv5/program.c +++ b/cv5/program.c @@ -17,16 +17,16 @@ int pridajHlas(char* meno, int pocetHlasov) { for (int i = 0; i < pocetStudentov; i++) { if (strcmp(studenti[i].meno, meno) == 0) { studenti[i].hlasy += pocetHlasov; - return 0; + return 0; } } if (pocetStudentov < MAX_STUDENTOV) { strcpy(studenti[pocetStudentov].meno, meno); studenti[pocetStudentov].hlasy = pocetHlasov; pocetStudentov++; - return 0; + return 0; } - return 1; + return 1; } int porovnaj(const void* a, const void* b) { @@ -43,6 +43,7 @@ int main() { char riadok[150]; char meno[MAX_MENO]; int pocetHlasov; + int validneZaznamy = 0; while (fgets(riadok, sizeof(riadok), stdin)) { if (sscanf(riadok, "%d %[^\n]s", &pocetHlasov, meno) == 2) { @@ -50,11 +51,19 @@ int main() { printf("Nepodarilo sa pridaƄ hlas.\n"); return 1; } + validneZaznamy = 1; } else { + break; } } + if (!validneZaznamy) { + + printf("Nepodarilo nacitat nic\n"); + return 1; + } + qsort(studenti, pocetStudentov, sizeof(Student), porovnaj); printf("Vysledky:\n");