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]); }