Project Of CONTACT MANAGEMENT SYSTEM IN C PROGRAMMING WITH SOURCE CODE
File handling, data structure, functions, and pointers are the main things which make up this simple c mini project The key features of contact management system are listed below:
- Add new contacts: with information such as name, phone number, address, and email
- List all contacts: lists all the contacts stored in file with their respective contact details
- Search contacts: based on name and phone number
- Edit contacts: edit information given while adding the contacts – name, phone number, address, and email
AUTHOR: UNKNOWN
SIZE OF FILE: UNKNOWN
NUMBER OF PAGES:UNKNOWN
LANGUAGE: ENGLISH
CATEGORY : PROJECT
PAGE QUALITY: GOOD
Project Of Contact Management System in ‘C’ Language Download Link
A Contact Management System (CMS) is a useful project for managing contact information like names, phone numbers, and email addresses. Here's a complete C program for a basic CMS with functionalities such as adding, searching, listing, and deleting contacts.
Features:
- Add a Contact: Store contact information.
- List Contacts: Display all saved contacts.
- Search Contacts: Find a contact by name.
- Delete a Contact: Remove a contact by name.
- Exit: Save and close the program.
Source Code
Here’s the complete implementation:
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#define MAX 100
#define NAME_LEN 50
#define PHONE_LEN 15
#define EMAIL_LEN 50
typedef struct {
char name[NAME_LEN];
char phone[PHONE_LEN];
char email[EMAIL_LEN];
} Contact;
Contact contacts[MAX];
int totalContacts = 0;
void addContact() {
if (totalContacts >= MAX) {
printf("Contact list is full!\n");
return;
}
printf("Enter Name: ");
scanf(" %[^\n]", contacts[totalContacts].name);
printf("Enter Phone: ");
scanf("%s", contacts[totalContacts].phone);
printf("Enter Email: ");
scanf("%s", contacts[totalContacts].email);
totalContacts++;
printf("Contact added successfully!\n");
}
void listContacts() {
if (totalContacts == 0) {
printf("No contacts available.\n");
return;
}
printf("\nList of Contacts:\n");
printf("---------------------------------------------------\n");
printf("%-20s %-15s %-30s\n", "Name", "Phone", "Email");
printf("---------------------------------------------------\n");
for (int i = 0; i < totalContacts; i++) {
printf("%-20s %-15s %-30s\n", contacts[i].name, contacts[i].phone, contacts[i].email);
}
printf("---------------------------------------------------\n");
}
void searchContact() {
char searchName[NAME_LEN];
printf("Enter name to search: ");
scanf(" %[^\n]", searchName);
int found = 0;
for (int i = 0; i < totalContacts; i++) {
if (strcmp(contacts[i].name, searchName) == 0) {
printf("\nContact Found:\n");
printf("Name: %s\n", contacts[i].name);
printf("Phone: %s\n", contacts[i].phone);
printf("Email: %s\n", contacts[i].email);
found = 1;
break;
}
}
if (!found) {
printf("Contact not found.\n");
}
}
void deleteContact() {
char deleteName[NAME_LEN];
printf("Enter name to delete: ");
scanf(" %[^\n]", deleteName);
int found = 0;
for (int i = 0; i < totalContacts; i++) {
if (strcmp(contacts[i].name, deleteName) == 0) {
for (int j = i; j < totalContacts - 1; j++) {
contacts[j] = contacts[j + 1];
}
totalContacts--;
printf("Contact deleted successfully!\n");
found = 1;
break;
}
}
if (!found) {
printf("Contact not found.\n");
}
}
void saveContactsToFile() {
FILE *file = fopen("contacts.dat", "wb");
if (file == NULL) {
printf("Error saving contacts!\n");
return;
}
fwrite(&totalContacts, sizeof(int), 1, file);
fwrite(contacts, sizeof(Contact), totalContacts, file);
fclose(file);
}
void loadContactsFromFile() {
FILE *file = fopen("contacts.dat", "rb");
if (file != NULL) {
fread(&totalContacts, sizeof(int), 1, file);
fread(contacts, sizeof(Contact), totalContacts, file);
fclose(file);
}
}
int main() {
int choice;
loadContactsFromFile();
do {
printf("\nContact Management System\n");
printf("1. Add Contact\n");
printf("2. List Contacts\n");
printf("3. Search Contact\n");
printf("4. Delete Contact\n");
printf("5. Exit\n");
printf("Enter your choice: ");
scanf("%d", &choice);
switch (choice) {
case 1:
addContact();
break;
case 2:
listContacts();
break;
case 3:
searchContact();
break;
case 4:
deleteContact();
break;
case 5:
saveContactsToFile();
printf("Exiting the program. Goodbye!\n");
break;
default:
printf("Invalid choice. Please try again.\n");
}
} while (choice != 5);
return 0;
}
Key Features:
- Data Persistence: Contacts are saved to a file (
contacts.dat
) and loaded automatically when the program starts. - User-Friendly Interface: Easy-to-use menu-driven approach.
Compilation and Execution:
- Save the code in a file named
contact_management.c
. - Compile it using:
gcc contact_management.c -o contact_management
- Run the program:
./contact_management
This program is simple yet functional and can be extended to include additional features like contact sorting, advanced search options, or a graphical interface.