0% found this document useful (0 votes)
20 views24 pages

Contact Management System in C - Javatpoint

Contact mangement

Uploaded by

Ajay Jaadi
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
20 views24 pages

Contact Management System in C - Javatpoint

Contact mangement

Uploaded by

Ajay Jaadi
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 24

Home C C++ C# Java SQL HTML CSS JavaScript XML Ajax Android Cloud

ADVERTISEMENT
Contact Management System in C
ADVERTISEMENT

This C contact management system project was written in C


programming language and is a console application. This system was
built as a straightforward side project in the Code::Blocks IDE using the
GCC compiler. The Contact Management System console software is a
simple tool with no graphics.

Similar to how contact management works on mobile devices. You can


add, view, edit, search and delete contacts in this project. A file is
maintained for each record that was added or modified. A simple
project for beginners to learn how to create a web project in C is
Contact Management System in C. The entire source code of the C
project will be made available to you, so you can quickly install it on
your computer and start learning how to program in C.

ADVERTISEMENT

The basis of a contact management system is the idea of creating


personal or organizational records of contacts, adding this data and
updating it. Here, users can add their contact information securely and
quickly. The system makes it easy to keep records of each person. The
entire project was developed using the "C" programming language and
various variables and strings. Consumers will find this little project easy
to use and understand. It is a simple terminal program created in C
without using any visual elements.

About the System

Add new contacts by entering details such as name, phone,


address and email.

Show all contacts: displays a list of information about each


contact from the file where they are stored.

Contacts can be searched using their name and phone number.

Edit Contacts: When adding contacts, you can change the name,
phone number, address and email.

Contacts are deleted by deleting them from the file.

Add new contacts by entering details such as name, phone,


address and email.

Name each contact: includes each contact in the file along with
their individual contact information.

Contacts can be searched using their name and phone number.

Edit Contacts: When adding contacts, you can change the name,
phone number, address and email.

Contacts are deleted by deleting them from the file.

Program Breakdown
struct contact
{
long ph ;
char name [ 20 ] , add [ 20 ] , email [ 30 ] ;
} list ;

Created a structure for our contact list.

system ( " cls " ) ; / * * * * * * * * Main menu * * * * * * * * * * * /

printf ( " \ n \ t * * * * Welcome to Contact Management System * * *

printf ( " \ n \ n \ n \ t \ t \ t MAIN MENU \ n \ t \ t = = = = = = = = = =\ n


printf ( " Enter the choice : " ) ;
scanf ( " % d " , &ch ) ;

The driver code looks something like above code which will display the
main menu of the contact management system in C having options to
add a new contact, list all contacts, search for contacts, edit a contact,
and delete a contact and exit.
case 1 :
system ( " cls " ) ;
fp = fopen ( " contact . dll " , " a " ) ;
for ( ; ; )
{
fflush ( stdin ) ;
printf ( " To exit enter blank space in the name input \ n Name ( U
scanf ( " % [ ^ \ n ] " , & list . name ) ;
if ( stricmp ( list . name , " " ) = = 0 | | stricmp ( list . name , " " ) =
break ;
fflush ( stdin ) ;
printf ( " Phone : " ) ;
scanf ( " % l d " , & list . ph ) ;
fflush ( stdi ) ;
printf ( " address : " ) ;
scanf ( " % [ ^ \ n ] " , & list . add ) ;
fflush ( stdin ) ;
printf ( " email address : " ) ;
gets ( list . email ) ;
printf ( " \ n " ) ;
fwrite ( & list , sizeof ( list ) , 1 , fp ) ;
}
fclose ( fp ) ;
break ;
If the user has selected the option 1 i.e. to add a contact then the
above code will come in action.

case 2 :
system ( " cls " ) ;
printf ( " \ n \ t \ t = = = = = = = = = = = = = = = \ n \ t \ t \ t LIST OF C
mail ad.\n= = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = =
for ( i = 97 ; i < = 122 ; i = i + 1 )
{
fp = fopen ( " contact . dll " , " r " ) ;
fflush ( stdin ) ;
found = 0 ;
while ( fread ( & list , sizeof ( list ) , 1 , fp ) = = 1 )
{
if ( list . name [ 0 ] = = i | | list . name [ 0 ] = = i - 32 )
{
printf ( " \ n Name \ t : % s \ n Phone \ t : % l d \ n Address \
list . ph , list . add , list . email ) ;
found + + ;
}
}
if ( found ! = 0 )
{
printf ( " = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = =
getch ( ) ;
}
fclose ( fp ) ;
}
break ;

The above code is used to display the contact list entered by the user.

case 3 :
system ( " cls " ) ;
do
{
found = 0 ;
printf ( " \ n \ n \ t . . : : CONTACT SEARCH \ n \ t = = = = = = = = =
fflush ( stdin ) ;
scanf ( " % [ ^ \ n ] " , & query ) ;
l = strlen ( query ) ;
fp = fopen ( " contact . dll " , " r " ) ;
system ( " cls " ) ;
printf ( " \ n \ n . . : : Search result for ' % s ' \ n = = = = = = = = = =
while ( fread ( & list , sizeof ( list ) , 1 , fp ) = = 1 )
{
for ( i = 0 ; i < = l ; i + + )
name [ i ] = list . name [ i ] ;
name [ l ] = ' \ 0 ' ;
if ( stricmp ( name , query ) = = 0 )
{
printf ( " \ n . . : : Name \ t : % s \ n . . : : Phone \ t : % l d \ n .
found + + ;
if ( found % 4 = = 0 )
{
printf ( " . . : : Press any key to continue... " ) ;
getch ( ) ;
}
}
}
if ( found = = 0 )
printf ( " \ n . . : : No match found! " ) ;
else
printf ( " \ n . . : : % d match ( s ) found ! " , found ) ;
fclose ( fp ) ;
printf ( " \ n . . : : Try again ? \ n \ n \ t [ 1 ] Yes \ t \ t [ 0 ] No \ n \
scanf ( " % d " , & ch ) ;
} while ( ch = = 1 ) ;
break ;

If the user wants to search for a contact then the above code will come
in action.

case 4 :
system ( " cls " ) ;
fp = fopen ( " contact . dll " , " r " ) ;

ft = fopen ( " temp . dat " , " w " ) ;

fflush ( stdin ) ;

printf ( " . . : : Edit contact \ n = = = = = = = = = = = = = = = = = = = = =

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

while ( fread ( & list , sizeof ( list ) , 1 , fp ) = = 1 )

if ( stricmp ( name , list . name ) ! = 0 )

fwrite ( & list , sizeof ( list ) , 1 , ft ) ;


}

fflush ( stdin ) ;

printf ( " \ n \ n . . : : Editing ' % s ' \ n \ n " , name ) ;

printf ( " . . : : Name ( Use identical ) : " ) ;

scanf ( " % [ ^ \ n ] " , & list . name ) ;

fflush ( stdin ) ;

printf ( " . . : : Phone : " ) ;

scanf ( " % l d " , & list . ph ) ;

fflush ( stdin ) ;

printf ( " . . : : address : " ) ;

scanf ( " % [ ^ \ n ] " , & list . add ) ;


fflush ( stdin ) ;

printf ( " . . : : email address : " ) ;

gets ( list . email ) ;

printf ( " \ n " ) ;

fwrite ( & list , sizeof ( list ) , 1 , ft ) ;

fclose ( fp ) ;

fclose ( ft ) ;

remove ( " contact . dll " ) ;

rename ( " temp . dat " , " contact . dll " ) ;

break ;

If the user wants to edit an existing contact then the above code will
come in action.

case 5 :
system ( " cls " ) ;
fflush ( stdin ) ;
printf ( " \ n \ n \ t . . : : DELETE A CONTACT \ n \ t = = = = = = = = =
scanf ( " % [ ^ \ n ] " , & name ) ;
fp = fopen ( " contact . dll " , " r " ) ;
ft = fopen ( " temp . dat " , " w " ) ;
while ( fread ( & list , sizeof ( list ) , 1 , fp ) ! = 0 )
if ( stricmp ( name , list . name ) ! = 0 )
fwrite ( & list , sizeof ( list ) , 1 , ft ) ;
fclose ( fp ) ;
fclose ( ft ) ;
remove ( " contact . dll " ) ;
rename ( " temp . dat " , " contact . dll " ) ;
break ;
default :
printf ( " Invalid choice " ) ;
break ;
}
printf ( " \ n \ n \ n . . : : Enter the Choice : \ n \ n \ t [ 1 ] Main Menu \ t
scanf ( " % d " , & ch ) ;
switch ( ch )
{
case 1 :
goto main ;
case 0 :
break ;
default :
printf ( " Invalid choice " ) ;
break ;
}
return 0 ;
}

If the user wants to delete a contact from the list then the above code
will come in action.

Program for Contact Management System in


C

#include <stdio.h>

#include <conio.h>

#include <string.h>

#include <process.h>

#include <stdlib.h>

#include <dos.h>

struct contact

{
long ph;

char name[20], add[20], email[30];

} list;

char query[20], name[20];

FILE *fp, *ft;

int i, n, ch, l, found;

int main()

main:

system("cls"); /* ************Main menu *********************** */

printf("\n\t **** Welcome to Contact Management System ****");

printf("\n\n\n\t\t\tMAIN MENU\n\t\t=====================\n\t\t

printf("Enter the choice:");

scanf("%d", &ch);

switch (ch)

case 0:

printf("\n\n\t\tAre you sure you want to exit?");

break;

/* *********************Add new contacts************ */


case 1:

system("cls");

fp = fopen("contact.dll", "a");

for (;;)

{
fflush(stdin);

printf("To exit enter blank space in the name input\nName (Use

scanf("%[^\n]", &list.name);

if (stricmp(list.name, "") == 0 || stricmp(list.name, " ") == 0)

break;

fflush(stdin);

printf("Phone:");

scanf("%ld", &list.ph);

fflush(stdin);

printf("address:");

scanf("%[^\n]", &list.add);

fflush(stdin);

printf("email address:");

gets(list.email);

printf("\n");
fwrite(&list, sizeof(list), 1, fp);
}

fclose(fp);

break;

/* * * * * * * * * * * * * * * * * *list of contacts* * * * * * * * * * * * * * * * * *
case 2:
system("cls");

printf("\n\t\t================================\n\t\t\tLIST O
mail ad.\n=================================================

for (i = 97; i <= 122; i = i + 1)

fp = fopen("contact.dll", "r");

fflush(stdin);

found = 0;

while (fread(&list, sizeof(list), 1, fp) == 1)

if (list.name[0] == i || list.name[0] == i - 32)

printf("\nName\t: %s\nPhone\t: %ld\nAddress\t: %s\nEmail

list.ph, list.add, list.email);

found++;
}
}
if (found != 0)

{
printf("============================================
(%d)\n\n", i - 32, found);

getch();
}

fclose(fp);
}

break;

/* *******************search contacts********************** */

case 3:

system("cls");

do

found = 0;

printf("\n\n\t..::CONTACT SEARCH\n\t=====================

fflush(stdin);

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

l = strlen(query);

fp = fopen("contact.dll", "r");

system("cls");

printf("\n\n..::Search result for '%s' \n======================


while (fread(&list, sizeof(list), 1, fp) == 1)

for (i = 0; i <= l; i++)

name[i] = list.name[i];

name[l] = '\0';

if (stricmp(name, query) == 0)

printf("\n..::Name\t: %s\n..::Phone\t: %ld\n..::Address\t: %s\

found++;

if (found % 4 == 0)

printf("..::Press any key to continue...");

getch();
}
}
}

if (found == 0)

printf("\n..::No match found!");

else

printf("\n..::%d match(s) found!", found);

fclose(fp);

printf("\n ..::Try again?\n\n\t[1] Yes\t\t[0] No\n\t");


scanf("%d", &ch);

} while (ch == 1);

break;

/* *********************edit contacts************************/

case 4:

system("cls");

fp = fopen("contact.dll", "r");

ft = fopen("temp.dat", "w");

fflush(stdin);

printf("..::Edit contact\n===============================\n\n

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

while (fread(&list, sizeof(list), 1, fp) == 1)

if (stricmp(name, list.name) != 0)

fwrite(&list, sizeof(list), 1, ft);


}

fflush(stdin);

printf("\n\n..::Editing '%s'\n\n", name);

printf("..::Name(Use identical):");

scanf("%[^\n]", &list.name);
fflush(stdin);

printf("..::Phone:");

scanf("%ld", &list.ph);

fflush(stdin);

printf("..::address:");

scanf("%[^\n]", &list.add);

fflush(stdin);

printf("..::email address:");

gets(list.email);

printf("\n");

fwrite(&list, sizeof(list), 1, ft);

fclose(fp);

fclose(ft);

remove("contact.dll");

rename("temp.dat", "contact.dll");

break;
/* * * * * * * * * * * * * * * * * * * * * delete contacts * * * * * * * * * * * * * *

case 5:

system("cls");

fflush(stdin);

printf("\n\n\t..::DELETE A CONTACT\n\t=====================
scanf("%[^\n]", &name);

fp = fopen("contact.dll", "r");

ft = fopen("temp.dat", "w");

while (fread(&list, sizeof(list), 1, fp) != 0)

if (stricmp(name, list.name) != 0)

fwrite(&list, sizeof(list), 1, ft);

fclose(fp);

fclose(ft);

remove("contact.dll");

rename("temp.dat", "contact.dll");

break;

default:

printf("Invalid choice");

break;
}

printf("\n\n\n..::Enter the Choice:\n\n\t[1] Main Menu\t\t[0] Exit\n");

scanf("%d", &ch);

switch (ch)

case 1:
goto main;

case 0:

break;

default:

printf("Invalid choice");

break;
}

return 0;
}

OUTPUT:

**** Welcome to Contact Management System ****

MAIN MENU
=====================
[1] Add a new Contact
[2] List all Contacts
[3] Search for contact
[4] Edit a Contact
[5] Delete a Contact
[0] Exit
= = = = = = = = = = = = = = = = =
Enter the choice:
To exit enter blank space in the name input
Name (Use identical):Vikas
Phone:123456789
address:A block
email address:[email protected]

To exit enter blank space in the name input


Name (Use identical):Vivan
Phone:546738546
address:C Block
email address:[email protected]

To exit enter blank space in the name input


Name (Use identical):

..::Enter the Choice:

[1] Main Menu [0] Exit


1

= = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = =
LIST OF CONTACTS
= = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = =
Name Phone No Address E-mail ad.
= = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = =
Name : Vikas
Phone : 123456789
Address : A block
Email : [email protected]

Name : Vivan
Phone : 546738546
Address : C Block
Email : [email protected]
= = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = [ V ] - ( 2 )
. . : : Search result for 'Vikas'
= = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = =
. . : : Name : Vikas
. . : : Phone : 123456789
. . : : Address : A block
. . : : Email : [email protected]

. . : : 1 match(s) found!
. . : : Try again?
[1] Yes [0] No
. . : : Search result for 'Vivan'
= = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = =
. . : : Name : Vivan
. . : : Phone : 546738546
. . : : Address : C Block
. . : : Email : [email protected]
. . : : 1 match(s) found!
. . : : Try again?

[1] Yes [0] No


. . : : DELETE A CONTACT
= = = = = = = = = = = = = = = = = =
. . : : Enter the name of contact to delete:Vikas

← Prev Next →

Youtube For Videos Join Our Youtube Channel: Join


Now

Feedback

Send your Feedback to [email protected]

Help Others, Please Share

Learn Latest Tutorials

Splunk SPSS tutorial Swagger


tutorial tutorial
SPSS
Splunk Swagger

T-SQL Tumblr React tutorial


tutorial tutorial ReactJS
Transact-SQL Tumblr

Regex R
tutorial Reinforcement Programming
learning tutorial
Regex
tutorial
R Programming
Reinforcement
RxJS tutorial
Learning React Native Python
tutorial Design Patterns
RxJS
React Native Python Design
Patterns

Python Python Keras


Pillow tutorial Turtle tutorial tutorial
Python Pillow Python Turtle Keras

Preparation

Aptitude Logical Verbal


Aptitude
Reasoning Ability
Reasoning Verbal Ability

Interview Company
Questions Interview
Interview
Questions
Questions Company
Questions

Trending Technologies

Artificial AWS Tutorial Selenium


Intelligence tutorial
AWS
Artificial Selenium
Intelligence

Cloud Hadoop ReactJS


Computing tutorial Tutorial
Cloud Computing Hadoop ReactJS

Data Science Angular 7 Blockchain


Tutorial Tutorial Tutorial
Data Science Angular 7 Blockchain
Git Tutorial Machine DevOps
Git
Learning Tutorial
Tutorial
DevOps
Machine
Learning

B.Tech / MCA

DBMS Data DAA tutorial


tutorial Structures
DAA
DBMS
tutorial
Data Structures

Operating Computer Compiler


System Network Design tutorial
Operating
tutorial Compiler Design
System Computer
Network

Computer Discrete Ethical


Organization Mathematics Hacking
and Tutorial
Ethical Hacking
Architecture
Discrete
Computer Mathematics
Organization
Computer Software html tutorial
Graphics Engineering
Web Technology
Tutorial
Software
Computer Engineering
Graphics

Cyber Automata C Language


Security Tutorial tutorial
tutorial
Automata C Programming
Cyber Security

C++ tutorial Java tutorial .Net


Framework
C++ Java
tutorial
.Net

Python List of Control


tutorial Programs Systems
tutorial
Python Programs
Control System
Data Mining Data
Tutorial Warehouse
Tutorial
Data Mining
Data Warehouse

You might also like