From 1b2674b5600cb2a6836c83e67f21d11c3584b93a Mon Sep 17 00:00:00 2001 From: ak643du Date: Thu, 25 Apr 2024 19:04:21 +0200 Subject: [PATCH] Initialization --- cv10/program.c | 18 +++++++----------- 1 file changed, 7 insertions(+), 11 deletions(-) diff --git a/cv10/program.c b/cv10/program.c index 129c134..254b9d6 100644 --- a/cv10/program.c +++ b/cv10/program.c @@ -2,6 +2,10 @@ #include #include +int compare_names(const void *a, const void *b) { + return strcmp(*(const char **)a, *(const char **)b); +} + int main() { int count; char buffer[100]; @@ -44,23 +48,15 @@ int main() { } // Sort the applications alphabetically - for (int m = 0; m < i - 1; m++) { - for (int n = m + 1; n < i; n++) { - if (strcmp(applications[m], applications[n]) > 0) { - char *temp = applications[m]; - applications[m] = applications[n]; - applications[n] = temp; - } - } - } + qsort(applications, i, sizeof(char *), compare_names); - printf("Prijati studenti:"); + printf("Prijati studenti:\n"); for (j = 0; j < (count < i ? count : i); j++) { printf("%s\n", applications[j]); } if (count < i) { - printf("Neprijati studenti:"); + printf("Neprijati studenti:\n"); for (; j < i; j++) { printf("%s\n", applications[j]); }