From 12c2205df55bbe7e115067bfeb99dd7df1ee8065 Mon Sep 17 00:00:00 2001 From: st529yr Date: Fri, 22 Mar 2024 08:23:35 +0100 Subject: [PATCH] funguje --- cv5/program.c | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/cv5/program.c b/cv5/program.c index 5baad49..058198e 100644 --- a/cv5/program.c +++ b/cv5/program.c @@ -30,6 +30,7 @@ int read_students(struct Student students[], int max_students) { while (fgets(line, sizeof(line), stdin) != NULL) { int votes; char name[MAX_SIZE]; + // Ak sa nenačítajú dva prvky (počet hlasov a meno), skončíme if (sscanf(line, "%d %99[^\n]", &votes, name) == 2) { strcpy(students[num_students].name, name); students[num_students].votes = votes; @@ -37,6 +38,14 @@ int read_students(struct Student students[], int max_students) { if (num_students >= max_students) { break; // Prekročený maximálny počet študentov } + } else if (sscanf(line, "%99[^\n]", name) == 1) { + // Ak sa nenačíta počet hlasov, nastavíme ho na 10 + strcpy(students[num_students].name, name); + students[num_students].votes = 10; // Predvolený počet hlasov + num_students++; + if (num_students >= max_students) { + break; // Prekročený maximálny počet študentov + } } } return num_students;