This commit is contained in:
Weber 2024-03-21 21:23:37 +00:00
parent c057acd40a
commit 80b02b2f26

View File

@ -31,6 +31,16 @@ int main() {
char name[1024]; char name[1024];
sscanf(line, "%d %[^\n]", &vote_count, name); sscanf(line, "%d %[^\n]", &vote_count, name);
int found = 0;
for (int i = 0; i < student_count; i++) {
if (strcmp(students[i].name, name) == 0) {
students[i].vote_count += vote_count;
found = 1;
break;
}
}
if (!found) {
if (student_count >= students_capacity) { if (student_count >= students_capacity) {
students_capacity = (students_capacity + 1) * 2; students_capacity = (students_capacity + 1) * 2;
student_t *new_students = realloc(students, students_capacity * sizeof(student_t)); student_t *new_students = realloc(students, students_capacity * sizeof(student_t));
@ -41,16 +51,6 @@ int main() {
students = new_students; students = new_students;
} }
int found = 0;
for (int i = 0; i < student_count; i++) {
if (strcmp(students[i].name, name) == 0) {
students[i].vote_count += vote_count; // Sčítaj nové hlasy k existujúcemu počtu hlasov študenta
found = 1;
break;
}
}
if (!found) {
students[student_count].name = strdup(name); students[student_count].name = strdup(name);
students[student_count].vote_count = vote_count; students[student_count].vote_count = vote_count;
student_count++; student_count++;