This commit is contained in:
Weber 2024-03-21 21:09:05 +00:00
parent 3b454f509a
commit 9850cd5463

View File

@ -8,8 +8,8 @@ typedef struct student {
} student_t; } student_t;
int compare_students(const void *a, const void *b) { int compare_students(const void *a, const void *b) {
const student_t *student_a = a; const student_t *student_a = (const student_t *)a;
const student_t *student_b = b; const student_t *student_b = (const student_t *)b;
if (student_a->vote_count > student_b->vote_count) { if (student_a->vote_count > student_b->vote_count) {
return -1; return -1;
@ -35,7 +35,7 @@ int main() {
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));
if (new_students == NULL) { if (new_students == NULL) {
fprintf(stderr, "Error"); fprintf(stderr, "Chyba");
return 1; return 1;
} }
students = new_students; students = new_students;
@ -51,9 +51,6 @@ int main() {
printf("Results:\n"); printf("Results:\n");
for (int i = 0; i < student_count; i++) { for (int i = 0; i < student_count; i++) {
printf("%d %s\n", students[i].vote_count, students[i].name); printf("%d %s\n", students[i].vote_count, students[i].name);
}
for (int i = 0; i < student_count; i++) {
free(students[i].name); free(students[i].name);
} }
free(students); free(students);