From 06701bbaee6869abdabb74da6e5106ca2625dda5 Mon Sep 17 00:00:00 2001 From: ak643du Date: Mon, 22 Apr 2024 19:19:03 +0200 Subject: [PATCH] Initialization --- cv10/program.c | 21 ++++++++++----------- 1 file changed, 10 insertions(+), 11 deletions(-) diff --git a/cv10/program.c b/cv10/program.c index c18af4a..fcc6775 100644 --- a/cv10/program.c +++ b/cv10/program.c @@ -5,8 +5,8 @@ #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 compareStrings(const void *a, const void *b) { + return strcmp((const char *)a, (const char *)b); } int main() { @@ -23,9 +23,11 @@ int main() { memset(names, 0, sizeof(names)); while (fgets(temp_name, sizeof(temp_name), stdin) != NULL && num_accepted < max_students) { - int i, found = 0; + // // Remove newline character if present + // temp_name[strcspn(temp_name, "\n")] = '\0'; + for (i = 0; i < num_accepted; i++) { if (strcmp(names[i], temp_name) == 0) { found = 1; @@ -40,20 +42,17 @@ int main() { num_students++; } - // Add a null character at the end of the names array - names[num_accepted][0] = '\0'; - - qsort(names, num_accepted, sizeof(names[0]), compare); - if (num_accepted == 0) { printf("Ziadne prihlasky"); } else { + qsort(names, num_accepted, sizeof(names[0]), compareStrings); + printf("Prijati studenti:\n"); for (int i = 0; i < num_accepted; i++) { - printf("%s", names[i]); + printf("%s\n", names[i]); } } - + // if (num_accepted < num_students) { // printf("Neprijati studenti:"); // for (int i = 0; i < max_students; i++) { @@ -64,4 +63,4 @@ int main() { // } return 0; -} \ No newline at end of file +}