“program”
This commit is contained in:
parent
85fbe3b98d
commit
7bd8fbba85
@ -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;
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user