“program”

This commit is contained in:
Vasylenko 2024-04-23 11:05:21 +02:00
parent 85fbe3b98d
commit 7bd8fbba85

View File

@ -32,14 +32,13 @@ int main() {
return 1; 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; name[strcspn(name, "\n")] = 0;
if (strlen(name) == 0) { if (strlen(name) == 0) {
break; break;
} }
int duplicate = 0; int duplicate = 0;
for (int i = 0; i < num_students; i++) { for (int i = 0; i < num_students; i++) {
if (strcmp(students[i], name) == 0) { if (strcmp(students[i], name) == 0) {
@ -49,6 +48,7 @@ int main() {
} }
if (!duplicate) { if (!duplicate) {
if (num_students < max_students) {
students[num_students] = strdup(name); students[num_students] = strdup(name);
if (students[num_students] == NULL) { if (students[num_students] == NULL) {
puts("Memory allocation failed"); puts("Memory allocation failed");
@ -58,6 +58,7 @@ int main() {
num_students++; num_students++;
} }
} }
}
if (num_students == 0) { if (num_students == 0) {
puts("Ziadne prihlasky"); puts("Ziadne prihlasky");
@ -69,18 +70,10 @@ int main() {
puts("Prijati studenti:"); puts("Prijati studenti:");
for (int i = 0; i < num_students; i++) { for (int i = 0; i < num_students; i++) {
if (i < max_students) {
puts(students[i]); puts(students[i]);
} else {
if (i == max_students) {
puts("Neprijati studenti:");
}
puts(students[i]);
}
} }
free_memory(students, num_students); free_memory(students, num_students);
return 0; return 0;
} }