“program”
This commit is contained in:
parent
a5ea74f79c
commit
b57c6d5ce9
@ -21,12 +21,14 @@ int main() {
|
||||
char **students = NULL;
|
||||
int num_students = 0;
|
||||
|
||||
|
||||
printf("Enter the maximum number of students that can be accepted: ");
|
||||
if (scanf("%d\n", &max_students) != 1 || max_students <= 0) {
|
||||
puts("Invalid input for the number of students.");
|
||||
return 1;
|
||||
}
|
||||
|
||||
|
||||
students = (char **)malloc(max_students * sizeof(char *));
|
||||
if (students == NULL) {
|
||||
puts("Memory allocation failed.");
|
||||
@ -34,20 +36,22 @@ int main() {
|
||||
}
|
||||
|
||||
printf("Enter student names (press Enter twice to stop):\n");
|
||||
while (fgets(name, MAX_NAME_LENGTH, stdin)) {
|
||||
if (name[strcspn(name, "\n")] = '\0', !*name)
|
||||
while (fgets(name, MAX_NAME_LENGTH, stdin) && num_students < max_students) {
|
||||
name[strcspn(name, "\n")] = '\0';
|
||||
if (strlen(name) == 0) {
|
||||
break;
|
||||
}
|
||||
|
||||
int is_duplicate = 0;
|
||||
|
||||
int duplicate = 0;
|
||||
for (int i = 0; i < num_students; i++) {
|
||||
if (strcmp(students[i], name) == 0) {
|
||||
is_duplicate = 1;
|
||||
duplicate = 1;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (!is_duplicate) {
|
||||
if (num_students < max_students) {
|
||||
if (!duplicate) {
|
||||
students[num_students] = strdup(name);
|
||||
if (students[num_students] == NULL) {
|
||||
puts("Memory allocation failed.");
|
||||
@ -57,7 +61,6 @@ int main() {
|
||||
num_students++;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (num_students == 0) {
|
||||
puts("No applications were received.");
|
||||
@ -76,4 +79,3 @@ int main() {
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user