From a4df11eb5901c3c3cc0bb243b404bcfa60710418 Mon Sep 17 00:00:00 2001 From: Weber Date: Fri, 22 Mar 2024 00:41:10 +0000 Subject: [PATCH] test --- cv5/program.c | 49 +++++++++++++++++++++++++------------------------ 1 file changed, 25 insertions(+), 24 deletions(-) diff --git a/cv5/program.c b/cv5/program.c index b4c8cea..368421f 100644 --- a/cv5/program.c +++ b/cv5/program.c @@ -35,37 +35,38 @@ int main() { if (student_count == 0) { total_votes = vote_count; - continue; - } - - int existing_student_index = -1; - for (int i = 0; i < student_count; i++) { - if (strcmp(students[i].name, name) == 0) { - existing_student_index = i; - break; - } - } - - if (existing_student_index != -1) { - students[existing_student_index].vote_count += vote_count; } else { - if (student_count >= students_capacity) { - students_capacity = (students_capacity + 1) * 2; - student_t *new_students = realloc(students, students_capacity * sizeof(student_t)); - if (new_students == NULL) { - fprintf(stderr, "Error: Memory reallocation failed\n"); - return 1; + int existing_student_index = -1; + for (int i = 0; i < student_count; i++) { + if (strcmp(students[i].name, name) == 0) { + existing_student_index = i; + break; } - students = new_students; } - students[student_count].name = strdup(name); - students[student_count].vote_count = vote_count; - student_count++; + if (existing_student_index != -1) { + students[existing_student_index].vote_count += vote_count; + } else { + if (student_count >= students_capacity) { + students_capacity = (students_capacity + 1) * 2; + student_t *new_students = realloc(students, students_capacity * sizeof(student_t)); + if (new_students == NULL) { + fprintf(stderr, "Error: Memory reallocation failed\n"); + return 1; + } + students = new_students; + } + + students[student_count].name = strdup(name); + students[student_count].vote_count = vote_count; + student_count++; + } } } - if (student_count == 1) { + if (student_count == 0) { + printf("Žiadni študenti.\n"); + } else if (student_count == 1) { printf("Vysledky:\n"); printf("%d %s\n", total_votes, students[0].name); } else {