“program”
This commit is contained in:
parent
85fbe3b98d
commit
7bd8fbba85
@ -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,13 +48,15 @@ int main() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (!duplicate) {
|
if (!duplicate) {
|
||||||
students[num_students] = strdup(name);
|
if (num_students < max_students) {
|
||||||
if (students[num_students] == NULL) {
|
students[num_students] = strdup(name);
|
||||||
puts("Memory allocation failed");
|
if (students[num_students] == NULL) {
|
||||||
free_memory(students, num_students);
|
puts("Memory allocation failed");
|
||||||
return 1;
|
free_memory(students, num_students);
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
num_students++;
|
||||||
}
|
}
|
||||||
num_students++;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -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;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user