-
Notifications
You must be signed in to change notification settings - Fork 9
/
Copy pathContactManagementSystem.c
72 lines (64 loc) · 2.17 KB
/
ContactManagementSystem.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
// ContactManagementSystem.c
#include <stdio.h>
#include <string.h>
#define MAX_CONTACTS 100
// Structure to represent a contact
struct Contact {
char name[50];
char phone[15];
char email[50];
};
// Function to display a contact
void displayContact(struct Contact contact) {
printf("Name: %s\n", contact.name);
printf("Phone: %s\n", contact.phone);
printf("Email: %s\n", contact.email);
}
int main() {
struct Contact contacts[MAX_CONTACTS];
int numContacts = 0;
int choice;
while (1) {
printf("Contact Management System\n");
printf("1. Add Contact\n");
printf("2. View Contacts\n");
printf("3. Exit\n");
printf("Enter your choice: ");
scanf("%d", &choice);
switch (choice) {
case 1:
if (numContacts < MAX_CONTACTS) {
struct Contact newContact;
printf("Enter Name: ");
scanf(" %[^\n]", newContact.name);
printf("Enter Phone: ");
scanf(" %[^\n]", newContact.phone);
printf("Enter Email: ");
scanf(" %[^\n]", newContact.email);
contacts[numContacts] = newContact;
numContacts++;
printf("Contact added successfully.\n");
} else {
printf("Contact limit reached. Cannot add more contacts.\n");
}
break;
case 2:
if (numContacts == 0) {
printf("No contacts available.\n");
} else {
printf("Contacts List:\n");
for (int i = 0; i < numContacts; i++) {
printf("Contact %d:\n", i + 1);
displayContact(contacts[i]);
}
}
break;
case 3:
printf("Exiting the Contact Management System.\n");
return 0;
default:
printf("Invalid choice. Please try again.\n");
}
}
return 0;
}