From 48511b4cc8948b703e7daceb225f1f26bde04cf1 Mon Sep 17 00:00:00 2001 From: ak643du Date: Thu, 25 Apr 2024 20:38:17 +0200 Subject: [PATCH] Initialization --- cv10/program.c | 24 ++++++++++++++---------- 1 file changed, 14 insertions(+), 10 deletions(-) diff --git a/cv10/program.c b/cv10/program.c index de71e14..a86f973 100644 --- a/cv10/program.c +++ b/cv10/program.c @@ -12,7 +12,7 @@ int main() { char **applications; int i, j; - if (scanf("%d", &count) != 1 || count <= 0) { + if (scanf("%d", &count)!= 1 || count <= 0) { printf("Nespravny vstup\n"); return 1; } @@ -42,8 +42,18 @@ int main() { } } + if (i!= count) { + printf("Nespravny vstup\n"); + for (j = 0; j < i; j++) { + free(applications[j]); + } + free(applications); + return 1; + } + if (i == 0) { printf("Ziadne prihlasky\n"); + free(applications); return 1; } @@ -52,15 +62,9 @@ int main() { printf("Prijati studenti:"); for (j = 0; j < i; j++) { - printf("%s\n", applications[j]); - } - - if (count < i) { - printf("Neprijati studenti:"); - for (; j < i; j++) { - printf("%s\n", applications[j]); - } + printf("\n%s", applications[j]); } + printf("\n"); // Free allocated memory for (j = 0; j < i; j++) { @@ -69,4 +73,4 @@ int main() { free(applications); return 0; -} +} \ No newline at end of file