#include <stdio.h>
#include <string.h>
#define MAX_PEOPLE 100
typedef struct {
char name[50];
int age;
// Add other relevant information about the person
} Person;
void displayPeople(Person people[], int count) {
printf("List of people:\n");
for (int i = 0; i < count; ++i) {
printf("%d. Name: %s, Age: %d\n", i + 1, people[i].name, people[i].age);
}
}
void addPerson(Person people[], int *count) {
if (*count < MAX_PEOPLE) {
printf("Enter name: ");
scanf("%s", people[*count].name);
printf("Enter age: ");
scanf("%d", &people[*count].age);
(*count)++;
printf("Person added successfully.\n");
} else {
printf("Maximum number of people reached.\n");
}
}
void removePerson(Person people[], int *count) {
if (*count > 0) {
displayPeople(people, *count);
int index;
printf("Enter the number of the person to remove: ");
scanf("%d", &index);
if (index > 0 && index <= *count) {
for (int i = index - 1; i < *count - 1; ++i) {
strcpy(people[i].name, people[i + 1].name);
people[i].age = people[i + 1].age;
}
(*count)--;
printf("Person removed successfully.\n");
} else {
printf("Invalid number. Please enter a valid number.\n");
}
} else {
printf("No people to remove.\n");
}
}
int main() {
Person people[MAX_PEOPLE];
int count = 0;
int choice;
do {
printf("\n1. Display People\n");
printf("2. Add Person\n");
printf("3. Remove Person\n");
printf("4. Exit\n");
printf("Enter your choice: ");
scanf("%d", &choice);
switch (choice) {
case 1:
displayPeople(people, count);
break;
case 2:
addPerson(people, &count);
break;
case 3:
removePerson(people, &count);
break;
case 4:
printf("Exiting program. Goodbye!\n");
break;
default:
printf("Invalid choice. Please enter a valid option.\n");
}
} while (choice != 4);
return 0;
}