From f8f468a3a82720e49f849773a06d3be91a53fa74 Mon Sep 17 00:00:00 2001 From: st529yr Date: Wed, 20 Mar 2024 17:31:33 +0100 Subject: [PATCH] funguje --- cv5/program.c | 37 +++++++++++++++++++------------------ 1 file changed, 19 insertions(+), 18 deletions(-) diff --git a/cv5/program.c b/cv5/program.c index f878b47..777b5fa 100644 --- a/cv5/program.c +++ b/cv5/program.c @@ -26,28 +26,29 @@ int main() { srand(time(NULL)); // Inicializácia generátora náhodných čísel - // Čítanie vstupu a vytváranie databázy - char input[SIZE]; - while (fgets(input, SIZE, stdin) != NULL) { - int votes; - char name[SIZE]; - sscanf(input, "%d %s %s", &votes, name, name + strlen(name) + 1); // Načítanie počtu hlasov, mena a priezviska + // Definícia vstupu + char input[] = "10 Terian Dis\n"; - int id = find_student(database, size, name); - if (id < 0) { - strcpy(database[size].name, name); - database[size].votes = votes; - size++; - } else { - database[id].votes += votes; - } + // Zobrazenie definície vstupu + printf("Vstup:\n%s\n", input); + + // Čítanie vstupu a vytváranie databázy + int votes; + char name[SIZE]; + sscanf(input, "%d %s %s", &votes, name, name + strlen(name) + 1); // Načítanie počtu hlasov, mena a priezviska + + int id = find_student(database, size, name); + if (id < 0) { + strcpy(database[size].name, name); + database[size].votes = votes; + size++; + } else { + database[id].votes += votes; } // Výpis databázy - printf("Databaza:\n"); - for (int i = 0; i < size; i++) { - printf("%d %s\n", database[i].votes, database[i].name); - } + printf("\nVysledky:\n"); + printf("%d %s\n", database[0].votes, database[0].name); return 0; }