Initialization

This commit is contained in:
Kozar 2024-04-25 19:04:21 +02:00
parent ac50e1467a
commit 1b2674b560

View File

@ -2,6 +2,10 @@
#include <stdlib.h>
#include <string.h>
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]);
}