From 541b4c92fae2fc2c2267f41b8499235b69bf2dfe Mon Sep 17 00:00:00 2001 From: ak643du Date: Mon, 22 Apr 2024 14:21:38 +0200 Subject: [PATCH] Initialization --- cv10/program.c | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/cv10/program.c b/cv10/program.c index 2f641a3..b27f25e 100644 --- a/cv10/program.c +++ b/cv10/program.c @@ -15,13 +15,12 @@ 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'; - } + // Remove newline character from temp_name + temp_name[strcspn(temp_name, "\n")] = '\0'; int i, found = 0; @@ -50,7 +49,7 @@ int main() { if (num_accepted < max_students) { printf("Neprijati studenti:\n"); for (int i = num_accepted; i < max_students; i++) { - printf("%s\n", names[i]); + printf("%s", names[i]); } }