From 19f7d1fe4c410fc1132bed06626acde177e7aab3 Mon Sep 17 00:00:00 2001 From: ak643du Date: Thu, 25 Apr 2024 21:03:39 +0200 Subject: [PATCH] Initialization --- cv10/program.c | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/cv10/program.c b/cv10/program.c index d18b0c9..e3e5a26 100644 --- a/cv10/program.c +++ b/cv10/program.c @@ -10,7 +10,7 @@ int main() { int count; char buffer[100]; char **applications; - int i, j; + int i, j, accepted_count = 0; if (scanf("%d", &count) != 1 || count <= 0) { printf("Nespravny vstup\n"); @@ -39,23 +39,24 @@ int main() { if (!found) { applications[i] = strdup(buffer); i++; + accepted_count++; } } - if (i == 0) { + if (accepted_count == 0) { printf("Ziadne prihlasky\n"); return 1; } // Sort the applications alphabetically - qsort(applications, i, sizeof(char *), compare_names); + qsort(applications, accepted_count, sizeof(char *), compare_names); printf("Prijati studenti:"); - for (j = 0; j < i; j++) { + for (j = 0; j < accepted_count; j++) { printf("%s\n", applications[j]); } - if (count > i) { + if (count < accepted_count) { printf("Neprijati studenti:"); for (; j < i; j++) { printf("%s\n", applications[j]); @@ -69,4 +70,4 @@ int main() { free(applications); return 0; -} +} \ No newline at end of file