funguje
This commit is contained in:
parent
327e8f8d5d
commit
12c2205df5
@ -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;
|
||||
|
Loading…
Reference in New Issue
Block a user