From 525ad77cc34c97e6fb6a27fc91d0c78bd0052954 Mon Sep 17 00:00:00 2001 From: ak643du Date: Thu, 25 Apr 2024 17:54:24 +0200 Subject: [PATCH] Initialization --- cv10/program.c | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/cv10/program.c b/cv10/program.c index 2203cfa..de10804 100644 --- a/cv10/program.c +++ b/cv10/program.c @@ -25,11 +25,10 @@ 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 the newline character from the temp_name array temp_name[strcspn(temp_name, "\n")] = '\0'; + int i, found = 0; for (i = 0; i < num_accepted; i++) { if (strcmp(names[i], temp_name) == 0) { found = 1; @@ -43,21 +42,22 @@ int main() { } num_students++; + // Check if we have reached the maximum number of accepted students if (num_accepted == max_students) { - break; + break; // Exit the loop } } qsort(names, num_accepted, sizeof(names[0]), compare_names); if (num_accepted == 0) { - printf("Ziadne prihlasky"); + printf("Ziadne prihlasky\n"); } else { printf("Prijati studenti:\n"); for (int i = 0; i < num_accepted; i++) { - printf("%s", names[i]); + printf("%s\n", names[i]); } } return 0; -} \ No newline at end of file +}