From 2484f0f10d372fb808247fd6ba244ac497bf6fc4 Mon Sep 17 00:00:00 2001 From: ak643du Date: Mon, 22 Apr 2024 18:30:47 +0200 Subject: [PATCH] Initialization --- cv10/program.c | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/cv10/program.c b/cv10/program.c index f8fd5bf..99f8116 100644 --- a/cv10/program.c +++ b/cv10/program.c @@ -15,9 +15,9 @@ int main() { return 1; } - memset(names, 0, sizeof(names)); - while (fgets(temp_name, sizeof(temp_name), stdin) != NULL && num_accepted < max_students) { + // Trim the newline character if present + temp_name[strcspn(temp_name, "\n")] = '\0'; int i, found = 0; @@ -38,20 +38,20 @@ int main() { if (num_accepted == 0) { printf("Ziadne prihlasky"); } else { - printf("Prijati studenti:"); + printf("Prijati studenti:\n"); for (int i = 0; i < num_accepted; i++) { - printf("%s", names[i]); + printf("%s\n", names[i]); } } - if (num_accepted < max_students) { - printf("Neprijati studenti:"); + if (num_accepted < max_students && num_accepted < num_students) { + printf("Neprijati studenti:\n"); for (int i = 0; i < max_students; i++) { if (names[i][0] == '\0') { - printf("%s", names[i]); + printf("%s\n", names[i]); } } } return 0; -} \ No newline at end of file +}