diff --git a/cv10/program.c b/cv10/program.c index ac3c104..d963cae 100644 --- a/cv10/program.c +++ b/cv10/program.c @@ -32,14 +32,13 @@ int main() { return 1; } - while (fgets(name, MAX_NAME_LENGTH, stdin) && num_students < max_students) { + while (fgets(name, MAX_NAME_LENGTH, stdin)) { name[strcspn(name, "\n")] = 0; if (strlen(name) == 0) { break; } - int duplicate = 0; for (int i = 0; i < num_students; i++) { if (strcmp(students[i], name) == 0) { @@ -49,13 +48,15 @@ int main() { } if (!duplicate) { - students[num_students] = strdup(name); - if (students[num_students] == NULL) { - puts("Memory allocation failed"); - free_memory(students, num_students); - return 1; + if (num_students < max_students) { + students[num_students] = strdup(name); + if (students[num_students] == NULL) { + puts("Memory allocation failed"); + free_memory(students, num_students); + return 1; + } + num_students++; } - num_students++; } } @@ -69,18 +70,10 @@ int main() { puts("Prijati studenti:"); for (int i = 0; i < num_students; i++) { - if (i < max_students) { - puts(students[i]); - } else { - if (i == max_students) { - puts("Neprijati studenti:"); - } - puts(students[i]); - } + puts(students[i]); } free_memory(students, num_students); return 0; } -