From 67dad58059ad968a6f643afc743ad69d785d94f9 Mon Sep 17 00:00:00 2001 From: ak643du Date: Mon, 22 Apr 2024 14:16:34 +0200 Subject: [PATCH] Initialization --- cv10/program.c | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/cv10/program.c b/cv10/program.c index 6d4d58f..3081a9f 100644 --- a/cv10/program.c +++ b/cv10/program.c @@ -15,10 +15,13 @@ int main() { return 1; } + // Initialize the names array to all-zero strings + memset(names, 0, sizeof(names)); + while (fgets(temp_name, sizeof(temp_name), stdin) != NULL && num_accepted < max_students) { size_t len = strlen(temp_name); if (len > 0 && temp_name[len-1] == '\n') { - temp_name[len-1] = '\0'; + temp_name[len-1] = '\0'; // remove newline character } int i, found = 0; @@ -41,16 +44,14 @@ int main() { } else { printf("Prijati studenti:\n"); for (int i = 0; i < num_accepted; i++) { - printf("%s", names[i]); - printf("\n"); + printf("%s\n", names[i]); } } if (num_accepted < max_students) { printf("Neprijati studenti:\n"); for (int i = num_accepted; i < max_students; i++) { - printf("%s", names[i]); - printf("\n"); + printf("%s\n", names[i]); } }