Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 24

CONTACT MANAGEMENT SYSTEM

Contact management system

GUIDE BY:-D.B.PATIL

VIDYAVARDHINI INSTIUTE OF TECHNOLOGY PAL

1
CONTACT MANAGEMENT SYSTEM

Data Structure using C:


In computer science, a data structure is a dataorganization, management,
and storage format that enablesefficient access and modification More
precisely, a data structureis a collection of data values, the relationships
among them, andthe functions or operations that can be applied to
the data i.e., itis an algebraic structure about data. It is a way to store
andorganize data so that it can be used efficiently.The data structure
name indicates itself that organizing the datain memory. There are many
ways of organizing the data in thememory as we have already seen one
of the data structures, i.e.,array in C language. Array is a collection of
memory elements inwhich data is stored sequentially, i.e., one after
another. In otherwords, we can say that array stores the elements in a
continuousmanner. There are also other ways to organize the data
inmemory.Data Structures using C means implementing Data
Structuresusing C language.

Types of Data Structure:


There are two types of data structures:1] Primitive data structure2] Non-
primitive
data structure-----------------------------------------------------------------------
-
1] Primitive Data structure:
The primitive data structures are primitive data types. The int, char,float,
double, and pointer are the primitive data structures that can holda single
value.

2] Non-Primitive Data structure


The non-primitive data structure is divided into two types:i.

VIDYAVARDHINI INSTIUTE OF TECHNOLOGY PAL

2
CONTACT MANAGEMENT SYSTEM

Linear data structureii.

Non-linear data structure

•Linear Data Structure:


The arrangement of data in a sequential manner is known as a lineardata
structure. The data structures used for this purpose are Arrays,Linked
list, Stacks, and Queues. In these data structures, one element
isconnected to only one another element in a linear form.

•Non Linear Data Structure:


Data structures where data elements are not arranged sequentially
orlinearly are called non-linear data structures. In a non-linear data
structure, single level is not involved. Therefore, we can’t traverse all
the elements in single run only. Non-linear data structures are not easyto
implement in comparison to linear data structure. It utilizes
computermemory efficiently in comparison to a linear data structure.
Itsexamples are trees, graphs, tables and sets.

•Data structures can also be classified as:

•Static data structure:


It is a type of data structure where the sizeis allocated at the compile
time. Therefore, the maximum size isfixed. Ex: Array

•Dynamic data structure

VIDYAVARDHINI INSTIUTE OF TECHNOLOGY PAL

3
CONTACT MANAGEMENT SYSTEM

: It is a type of data structure where thesize is allocated at the run time.


Therefore, the maximum size isflexible. Ex: Linked List, Queue, Stack
Types of Data Structure Diagram:

❖Contact Management System:

VIDYAVARDHINI INSTIUTE OF TECHNOLOGY PAL

4
CONTACT MANAGEMENT SYSTEM

So, by using the concept of Data Structure using C wehave prepared a


Contact Management System Project. It can beused to save our
contacts.Mainly we have used the concept of Linked list in this program
ofContact Management System. For each contact there is one nodeof
linked list and its number increases as new contacts are added tothe list.
Linked List:
A linked list is a linear data structure, in which theelements are not
stored at contiguous memory locations. Theelements in a linked list are
linked using pointers as shown in the below image:

VIDYAVARDHINI INSTIUTE OF TECHNOLOGY PAL

5
CONTACT MANAGEMENT SYSTEM

It is a sequence of links which contains items. Each link contains


aconnection to another link.All-important attributes of One Contact are
such as:

Name

Phone Number

Address

Email AddressAt beginning, there is a Main Menu which contains


variousOperation to perform those Options are such as:
1.

Add New Contact2.

List of All Contacts3.

Search for contact4.

Edit a Contact5.

Delete a Contact6.

Exit----------------------------------------------------------------------------------
--

VIDYAVARDHINI INSTIUTE OF TECHNOLOGY PAL

6
CONTACT MANAGEMENT SYSTEM

Soursc code:-

#include <stdio.h>

#include <string.h>

#define MAX_CONTACTS 100

// Structure to store contact information

struct Contact {

char name[50];

char phone[20];

char email[50];

char address[100];

};

// Function to add a new contact

void addContact(struct Contact contacts[], int *count) {

if (*count >= MAX_CONTACTS) {

printf("The contact list is full.\n");

return;

VIDYAVARDHINI INSTIUTE OF TECHNOLOGY PAL

7
CONTACT MANAGEMENT SYSTEM

printf("Enter contact details:\n");

printf("Name: ");

scanf(" %[^\n]", contacts[*count].name);

printf("Phone: ");

scanf(" %[^\n]", contacts[*count].phone);

printf("Email: ");

scanf(" %[^\n]", contacts[*count].email);

printf("Address: ");

scanf(" %[^\n]", contacts[*count].address);

(*count)++;

printf("Contact added successfully!\n");

// Function to list all contacts

void listContacts(struct Contact contacts[], int count) {

if (count == 0) {

printf("No contacts to display.\n");

return;

printf("Contact List:\n");

for (int i = 0; i < count; i++) {

printf("Contact %d:\n", i + 1);

VIDYAVARDHINI INSTIUTE OF TECHNOLOGY PAL

8
CONTACT MANAGEMENT SYSTEM

printf("Name: %s\n", contacts[i].name);

printf("Phone: %s\n", contacts[i].phone);

printf("Email: %s\n", contacts[i].email);

printf("Address: %s\n", contacts[i].address);

// Function to search for a contact by name

void searchContact(struct Contact contacts[], int count) {

if (count == 0) {

printf("No contacts to search.\n");

return;

char searchName[50];

printf("Enter the name to search for: ");

scanf(" %[^\n]", searchName);

int found = 0;

for (int i = 0; i < count; i++) {

if (strcmp(contacts[i].name, searchName) == 0) {

printf("Contact found:\n");

printf("Name: %s\n", contacts[i].name);

printf("Phone: %s\n", contacts[i].phone);

VIDYAVARDHINI INSTIUTE OF TECHNOLOGY PAL

9
CONTACT MANAGEMENT SYSTEM

printf("Email: %s\n", contacts[i].email);

printf("Address: %s\n", contacts[i].address);

found = 1;

break;

if (!found) {

printf("Contact not found.\n");

// Function to edit a contact by name

void editContact(struct Contact contacts[], int count) {

if (count == 0) {

printf("No contacts to edit.\n");

return;

char searchName[50];

printf("Enter the name of the contact to edit: ");

scanf(" %[^\n]", searchName);

int found = 0;

VIDYAVARDHINI INSTIUTE OF TECHNOLOGY PAL

10
CONTACT MANAGEMENT SYSTEM

for (int i = 0; i < count; i++) {

if (strcmp(contacts[i].name, searchName) == 0) {

printf("Enter the new details for the contact:\n");

printf("Name: ");

scanf(" %[^\n]", contacts[i].name);

printf("Phone: ");

scanf(" %[^\n]", contacts[i].phone);

printf("Email: ");

scanf(" %[^\n]", contacts[i].email);

printf("Address: ");

scanf(" %[^\n]", contacts[i].address);

printf("Contact edited successfully!\n");

found = 1;

break;

if (!found) {

printf("Contact not found.\n");

// Function to delete a contact by name

void deleteContact(struct Contact contacts[], int *count) {

VIDYAVARDHINI INSTIUTE OF TECHNOLOGY PAL

11
CONTACT MANAGEMENT SYSTEM

if (*count == 0) {

printf("No contacts to delete.\n");

return;

char searchName[50];

printf("Enter the name of the contact to delete: ");

scanf(" %[^\n]", searchName);

int found = 0;

for (int i = 0; i < *count; i++) {

if (strcmp(contacts[i].name, searchName) == 0) {

for (int j = i; j < *count - 1; j++) {

strcpy(contacts[j].name, contacts[j + 1].name);

strcpy(contacts[j].phone, contacts[j + 1].phone);

strcpy(contacts[j].email, contacts[j + 1].email);

strcpy(contacts[j].address, contacts[j + 1].address);

(*count)--;

printf("Contact deleted successfully!\n");

found = 1;

break;

VIDYAVARDHINI INSTIUTE OF TECHNOLOGY PAL

12
CONTACT MANAGEMENT SYSTEM

if (!found) {

printf("Contact not found.\n");

int main() {

struct Contact contacts[MAX_CONTACTS];

int count = 0;

int choice;

while (1) {

printf("\nContact Management System\n");

printf("1. Add a new contact\n");

printf("2. List all contacts\n");

printf("3. Search for a contact\n");

printf("4. Edit a contact\n");

printf("5. Delete a contact\n");

printf("6. Exit\n");

printf("Enter your choice: ");

scanf("%d", &choice);

switch (choice) {

case 1:

VIDYAVARDHINI INSTIUTE OF TECHNOLOGY PAL

13
CONTACT MANAGEMENT SYSTEM

addContact(contacts, &count);

break;

case 2:

listContacts(contacts, count);

break;

case 3:

searchContact(contacts, count);

break;

case 4:

editContact(contacts, count);

break;

case 5:

deleteContact(contacts, &count);

break;

case 6:

printf("Exiting the program.\n");

return 0;

default:

printf("Invalid choice. Please try again.\n");

return 0;

VIDYAVARDHINI INSTIUTE OF TECHNOLOGY PAL

14
CONTACT MANAGEMENT SYSTEM

❖Main Menu: [ Output Screenshot]

VIDYAVARDHINI INSTIUTE OF TECHNOLOGY PAL

15
CONTACT MANAGEMENT SYSTEM

1] Add a New Contact:


To add a new contact and save it we have toselect or Enter First Option
i.e. (1). Then enter Name, phone no, addressand Email address

VIDYAVARDHINI INSTIUTE OF TECHNOLOGY PAL

16
CONTACT MANAGEMENT SYSTEM

2] List of All Contacts:


To show thelist of all contacts there isSecond Option i.e.
(2). So here we have entered three contacts.

VIDYAVARDHINI INSTIUTE OF TECHNOLOGY PAL

17
CONTACT MANAGEMENT SYSTEM

3] Search for Contact:


To search any contact from saved list wehave to choose third option (3)

and then put the name of that contact..

VIDYAVARDHINI INSTIUTE OF TECHNOLOGY PAL

18
CONTACT MANAGEMENT SYSTEM

4] Edit a Contact:
To edit a previously saved contact there is optionnumber four i.e. (4).
We can change name, phone number, addressand email address means
all the attributes.

VIDYAVARDHINI INSTIUTE OF TECHNOLOGY PAL

19
CONTACT MANAGEMENT SYSTEM

List after Editing Contact:

VIDYAVARDHINI INSTIUTE OF TECHNOLOGY PAL

20
CONTACT MANAGEMENT SYSTEM

5] Delete a Contact:
To delete a particular contact we can use deleteoption number five (5).

Program asks us to enter the name of contactwhich we have to delete.


Before delete operation we have twocontacts Harshal and Nawazuddin.

VIDYAVARDHINI INSTIUTE OF TECHNOLOGY PAL

21
CONTACT MANAGEMENT SYSTEM

List of Contacts after delete operation: After Deletion there is


onlyone contact and another is deleted.

VIDYAVARDHINI INSTIUTE OF TECHNOLOGY PAL

22
CONTACT MANAGEMENT SYSTEM

6] Exit:
To Exit from the program we can use exit option (0).

VIDYAVARDHINI INSTIUTE OF TECHNOLOGY PAL

23
CONTACT MANAGEMENT SYSTEM

VIDYAVARDHINI INSTIUTE OF TECHNOLOGY PAL

24

You might also like