From a5ea74f79c7e8187febf425cfaa26060d2a59289 Mon Sep 17 00:00:00 2001 From: Vasylenko Date: Tue, 23 Apr 2024 11:13:00 +0200 Subject: [PATCH] =?UTF-8?q?=E2=80=9Cprogram=E2=80=9D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- cv10/program.c | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/cv10/program.c b/cv10/program.c index d963cae..4f97621 100644 --- a/cv10/program.c +++ b/cv10/program.c @@ -21,37 +21,36 @@ int main() { char **students = NULL; int num_students = 0; + printf("Enter the maximum number of students that can be accepted: "); if (scanf("%d\n", &max_students) != 1 || max_students <= 0) { - puts("Nespravny vstup"); + puts("Invalid input for the number of students."); return 1; } students = (char **)malloc(max_students * sizeof(char *)); if (students == NULL) { - puts("Memory allocation failed"); + puts("Memory allocation failed."); return 1; } + printf("Enter student names (press Enter twice to stop):\n"); while (fgets(name, MAX_NAME_LENGTH, stdin)) { - name[strcspn(name, "\n")] = 0; - - if (strlen(name) == 0) { + if (name[strcspn(name, "\n")] = '\0', !*name) break; - } - int duplicate = 0; + int is_duplicate = 0; for (int i = 0; i < num_students; i++) { if (strcmp(students[i], name) == 0) { - duplicate = 1; + is_duplicate = 1; break; } } - if (!duplicate) { + if (!is_duplicate) { if (num_students < max_students) { students[num_students] = strdup(name); if (students[num_students] == NULL) { - puts("Memory allocation failed"); + puts("Memory allocation failed."); free_memory(students, num_students); return 1; } @@ -61,14 +60,14 @@ int main() { } if (num_students == 0) { - puts("Ziadne prihlasky"); + puts("No applications were received."); free(students); return 1; } qsort(students, num_students, sizeof(char *), compare); - puts("Prijati studenti:"); + puts("Accepted students:"); for (int i = 0; i < num_students; i++) { puts(students[i]); } @@ -77,3 +76,4 @@ int main() { return 0; } +