Initialization

This commit is contained in:
Kozar 2024-04-25 17:47:40 +02:00
parent 9fdb2f3d35
commit 286056678a

View File

@ -24,11 +24,10 @@ int main() {
memset(names, 0, sizeof(names)); memset(names, 0, sizeof(names));
while (fgets(temp_name, sizeof(temp_name), stdin) != NULL && num_accepted < max_students) { while (fgets(temp_name, sizeof(temp_name), stdin)!= NULL && num_accepted < max_students) {
int i, found = 0; int i, found = 0;
// Remove the newline character from the temp_name array
temp_name[strcspn(temp_name, "\n")] = '\0'; temp_name[strcspn(temp_name, "\n")] = '\0';
for (i = 0; i < num_accepted; i++) { for (i = 0; i < num_accepted; i++) {
@ -38,15 +37,15 @@ int main() {
} }
} }
if (!found) { if (!found && num_accepted < MAX_STUDENTS) {
strcpy(names[num_accepted], temp_name); strcpy(names[num_accepted], temp_name);
num_accepted++; num_accepted++;
} }
num_students++; num_students++;
// Check if we have reached the maximum number of accepted students
if (num_accepted == max_students) { if (num_accepted == max_students) {
break; // Exit the loop break;
} }
} }