-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathContact Management System.c
74 lines (67 loc) · 2.04 KB
/
Contact Management System.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
73
74
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
// Define a structure to represent a contact
struct Contact {
char name[50];
char phone[15];
char email[50];
};
// Function to add a new contact
void addContact(struct Contact *contacts, int *count) {
if (*count < 100) { // Assuming you want to limit the number of contacts
struct Contact newContact;
printf("Enter Name: ");
scanf("%s", newContact.name);
printf("Enter Phone: ");
scanf("%s", newContact.phone);
printf("Enter Email: ");
scanf("%s", newContact.email);
contacts[*count] = newContact;
(*count)++;
printf("Contact added successfully!\n");
} else {
printf("Contact limit reached!\n");
}
}
// Function to display all contacts
void displayContacts(struct Contact *contacts, int count) {
if (count == 0) {
printf("No contacts found.\n");
} else {
printf("Contacts:\n");
for (int i = 0; i < count; i++) {
printf("Name: %s\n", contacts[i].name);
printf("Phone: %s\n", contacts[i].phone);
printf("Email: %s\n", contacts[i].email);
printf("-----------------\n");
}
}
}
int main() {
struct Contact contacts[100]; // Assuming a maximum of 100 contacts
int count = 0;
int choice;
do {
printf("\nContact Management System\n");
printf("1. Add Contact\n");
printf("2. Display Contacts\n");
printf("3. Exit\n");
printf("Enter your choice: ");
scanf("%d", &choice);
switch (choice) {
case 1:
addContact(contacts, &count);
break;
case 2:
displayContacts(contacts, count);
break;
case 3:
printf("Exiting...\n");
break;
default:
printf("Invalid choice. Try again.\n");
}
} while (choice != 3);
return 0;
}