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]);