From d9f495839071fa99628413358dbbfc86032f4f24 Mon Sep 17 00:00:00 2001 From: ak643du Date: Mon, 22 Apr 2024 19:15:04 +0200 Subject: [PATCH] Initialization --- cv10/program.c | 34 ++++++++++++++++------------------ 1 file changed, 16 insertions(+), 18 deletions(-) diff --git a/cv10/program.c b/cv10/program.c index 7541860..59ce60b 100644 --- a/cv10/program.c +++ b/cv10/program.c @@ -1,18 +1,20 @@ #include #include +#include #define MAX_STUDENTS 100 #define NAME_SIZE 50 +int compare(const void *a, const void *b) { + return strcmp(*(const char **)a, *(const char **)b); +} + int main() { int max_students, num_accepted = 0, num_students = 0; char names[MAX_STUDENTS][NAME_SIZE]; char temp_name[NAME_SIZE]; - printf("Zadajte maximalny pocet studentov: "); - fgets(temp_name, sizeof(temp_name), stdin); - max_students = atoi(temp_name); - + scanf("%d", &max_students); if (max_students <= 0 || max_students > MAX_STUDENTS) { printf("Nespravny vstup\n"); return 1; @@ -20,7 +22,6 @@ int main() { memset(names, 0, sizeof(names)); - printf("Zadajte mena studentov (maximalne %d):\n", max_students); while (fgets(temp_name, sizeof(temp_name), stdin) != NULL && num_accepted < max_students) { int i, found = 0; @@ -42,24 +43,21 @@ int main() { if (num_accepted == 0) { printf("Ziadne prihlasky"); } else { + qsort(names, num_accepted, sizeof(names[0]), compare); printf("Prijati studenti:\n"); - qsort(names, num_accepted, sizeof(names[0]), strcmp); for (int i = 0; i < num_accepted; i++) { printf("%s", names[i]); } } - - if (num_accepted < num_students) { - printf("Neprijati studenti:\n"); - for (int i = 0; i < max_students; i++) { - if (names[i][0] == '\0') { - continue; - } - if (num_accepted == 0 || strcmp(names[num_accepted - 1], names[i]) < 0) { - printf("%s", names[i]); - } - } - } + + // if (num_accepted < num_students) { + // printf("Neprijati studenti:"); + // for (int i = 0; i < max_students; i++) { + // if (names[i][0] == '\0') { + // printf("%s", names[i]); + // } + // } + // } return 0; } \ No newline at end of file