From ed42221d74d2aadfceafbc5d7d19d4be0643f3b7 Mon Sep 17 00:00:00 2001 From: ak643du Date: Thu, 25 Apr 2024 20:13:58 +0200 Subject: [PATCH] Initialization --- cv10/program.c | 16 ++++++---------- 1 file changed, 6 insertions(+), 10 deletions(-) diff --git a/cv10/program.c b/cv10/program.c index 54b92b0..4c9be8a 100644 --- a/cv10/program.c +++ b/cv10/program.c @@ -27,7 +27,11 @@ int main() { } // Načítanie prihlášok - while (scanf("%s", buffer) == 1 && buffer[0] != '\0') { + while (num_applications < max_students && fgets(buffer, sizeof(buffer), stdin) != NULL && buffer[0] != '\n') { + size_t len = strlen(buffer); + if (buffer[len - 1] == '\n') { + buffer[len - 1] = '\0'; // odstránenie koncového znaku nového riadku + } applications[num_applications] = strdup(buffer); if (applications[num_applications] == NULL) { puts("Chyba alokacie pamate"); @@ -48,18 +52,10 @@ int main() { // Výpis prijatých študentov puts("Prijati studenti:"); int i; - for (i = 0; i < num_applications && i < max_students; i++) { + for (i = 0; i < num_applications; i++) { printf("%s\n", applications[i]); } - // Výpis neprijatých študentov - if (i < num_applications) { - puts("Neprijati studenti:"); - for (; i < num_applications; i++) { - printf("%s\n", applications[i]); - } - } - // Uvoľnenie pamäte for (i = 0; i < num_applications; i++) { free(applications[i]);