Open navigation menu
Close suggestions
Search
Search
en
Change Language
Upload
Sign in
Sign in
Download free for days
0 ratings
0% found this document useful (0 votes)
10 views
PF Source Code
C programming project code for address book code .
Uploaded by
zunairatariq985
AI-enhanced title
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
Download now
Download
Save pf source code For Later
Download
Save
Save pf source code For Later
0%
0% found this document useful, undefined
0%
, undefined
Embed
Share
Print
Report
0 ratings
0% found this document useful (0 votes)
10 views
PF Source Code
C programming project code for address book code .
Uploaded by
zunairatariq985
AI-enhanced title
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
Download now
Download
Save pf source code For Later
Carousel Previous
Carousel Next
Save
Save pf source code For Later
0%
0% found this document useful, undefined
0%
, undefined
Embed
Share
Print
Report
Download now
Download
You are on page 1
/ 9
Search
Fullscreen
Title: File Management System
( Creating a Address book in C )
Source code:
#include <stdio.h>
#include <string.h>
struct Person {
char name[30];
char phone[30];
char email[30];
char address[30];
};
void addressbook(){
printf("\n--- Contact Management System ---\n");
printf("1. Add Contact\n");
printf("2. View all Contacts\n");
printf("3. View a specific contact\n");
printf("4. Delete Contact\n");
printf("5.change a contact\n");
printf("6. delete all contacts \n");
printf("7. Search a contact\n");
printf("8. Exit ");
}
void addContact() {
FILE *file = fopen("C:\\files\\contacts.txt", "a");
if (file == NULL)
{
perror("Error opening file");
return;
}
struct Person newPerson;
printf("Enter name: ");
scanf("%s", &newPerson.name);
printf("Enter phone number: ");
scanf("%s",&newPerson.phone);
printf("Enter email: ");
scanf("%s", &newPerson.email);
printf("Enter address: ");
scanf("%s", &newPerson.address);
fprintf(file, "%s %s %s %s ", newPerson.name, newPerson.phone, newPerson.email,newPerson.address);
fclose(file);
printf("Contact added successfully.\n");
}
void viewContacts() {
FILE *file = fopen("C:\\files\\contacts.txt", "r");
if (file == NULL) {
perror("Error opening file");
return;
}
struct Person currentPerson;
printf("Contacts:\n");
while (fscanf(file, "%s %s %s %s", ¤tPerson.name, ¤tPerson.phone,
¤tPerson.email,¤tPerson.address) != EOF) {
printf(" \n%s\n%s\n%s\n%s\n", currentPerson.name, currentPerson.phone,
currentPerson.email,currentPerson.address);
}
fclose(file);
}
void deleteContact() {
char name[30];
printf("Enter name to delete: ");
scanf("%s", &name);
FILE *file = fopen("C:\\files\\contacts.txt", "r");
FILE *tempFile = fopen("C:\\files\\temp.txt", "w");
struct Person currentPerson;
int found = 0;
while (fscanf(file, "%s %s %s %s", ¤tPerson.name, ¤tPerson.phone, ¤tPerson.email,
¤tPerson.address) != EOF)
{
if (strcmp(currentPerson.name, name) != 0)
{
fprintf(tempFile, "%s %s %s %s\n", currentPerson.name, currentPerson.phone,
currentPerson.email,currentPerson.address);
}
else {
found = 1;
}
}
fclose(file);
fclose(tempFile);
remove("C:\\files\\contacts.txt");
rename("C:\\files\\temp.txt", "C:\\files\\contacts.txt");
if (found)
{
printf("Contact '%s' deleted successfully.\n", name);
}
else {
printf("Contact '%s' not found.\n", name);
}
}
void deleteall() {
FILE *file = fopen("C:\\files\\contacts.txt", "r");
FILE *fprt = fopen("C:\\files\\temp.txt", "w");
fclose(file);
fclose(fprt);
remove("C:\\files\\contacts.txt");
rename("C:\\files\\temp.txt", "C:\\files\\contacts.txt");
printf("Contacts deleted successfully.\n");
}
void view(){
FILE *f = fopen("C:\\files\\contacts.txt", "r");
if (f == NULL)
{
perror("Error opening file");
return;
}
char nameToFind[30];
printf("Enter name to find: ");
scanf("%s", &nameToFind);
struct Person contact;
int found = 0;
while (fscanf(f, "%s %s ", &contact.name, &contact.phone)==2) {
if (strcmp(contact.name, nameToFind) == 0)
{
printf("Name: %s\nPhone: %s\n ", contact.name, contact.phone);
found = 1; }
}
if (found!=1)
{ printf("Contact not found\n");
}
fclose(f);
}
void editContact(){
struct Person contact;
FILE *f=fopen("C:\\files\\contacts.txt","r");
FILE *fprt=fopen("C:\\files\\tempFile.txt","w");
char name[30];
int found=0;
printf("enter the name to edit\n");
scanf("%s",&name);
while(fscanf(f, "%s %s %s %s",&contact.name,&contact.phone,&contact.email,&contact.address) == 4){
if(strcmp(contact.name,name)==0)
{
printf("enter new contact\n");
scanf("%s",&contact.name);
printf("enter new phone\n");
scanf("%s",&contact.phone);
printf("enter new email\n");
scanf("%s",&contact.email);
printf("enter new address\n");
scanf("%s",&contact.address);
found=1;
}
fprintf(fprt," %s %s %s %s ",contact.name,contact.email,contact.phone,contact.address);
}
fclose(f);
fclose(fprt);
remove("C:\\files\\contacts.txt");
rename("C:\\files\\tempFile.txt", "C:\\files\\contacts.txt");
}
void search(){
FILE*f=fopen("C:\\files\\contacts.txt","r");
struct Person contact;
char name[30];
printf("enter name to search");
scanf("%s",name);
while(fscanf(f, "%s %s %s %s",&contact.name,&contact.phone,&contact.email,&contact.address)==4){
if(strcmp(contact.name,name)==0
{ printf("%s %s %s %s",contact.name,contact.phone,contact.email,contact.address);
}
}
}
int main() {
int choice;
char name[30];
do {
addressbook();
printf("Enter your choice: ");
scanf("%d", &choice);
switch (choice) {
case 1: addContact();
break;
case 2: viewContacts();
break;
case 3: view();
break;
case 4: deleteContact();
break;
case 5: editContact();
break;
case 6: deleteall();
break;
case 7: search();
break;
case 8: printf("Exiting program. Goodbye!\n");
break;
default:
printf("Invalid choice. Please enter a valid option.\n");
}
} while (choice != 8);
return 0; }
Output:
Adding new contacts:
View all contacts:
View a specific contact:
Delete a specific contact:
Delete all contacts:
Adding anew contact +editing a new
contact:
Searching a contact:
Exiting the program:
You might also like
Contact Management Project
PDF
No ratings yet
Contact Management Project
9 pages
Contact Management System in C - Javatpoint
PDF
No ratings yet
Contact Management System in C - Javatpoint
24 pages
text
PDF
No ratings yet
text
3 pages
Menudriven Filehandling
PDF
No ratings yet
Menudriven Filehandling
3 pages
Index SR No Topic Page No
PDF
No ratings yet
Index SR No Topic Page No
13 pages
Address Book Program in C
PDF
75% (4)
Address Book Program in C
15 pages
Phone Book 2 Asign PRJ
PDF
No ratings yet
Phone Book 2 Asign PRJ
6 pages
Message (20)
PDF
No ratings yet
Message (20)
8 pages
Main 1
PDF
No ratings yet
Main 1
5 pages
BAKERY MANAGEMENT SYSTEM Project
PDF
50% (2)
BAKERY MANAGEMENT SYSTEM Project
24 pages
Slips Sloution Advanced C
PDF
No ratings yet
Slips Sloution Advanced C
24 pages
DSLK
PDF
No ratings yet
DSLK
6 pages
Adv C Slip Solution
PDF
No ratings yet
Adv C Slip Solution
31 pages
Csprog 2 Workingna
PDF
No ratings yet
Csprog 2 Workingna
9 pages
coding (1) (1)
PDF
No ratings yet
coding (1) (1)
29 pages
OMKAR j3
PDF
No ratings yet
OMKAR j3
3 pages
Assignment - 5: #Include
PDF
No ratings yet
Assignment - 5: #Include
6 pages
Compute Assisment 2
PDF
No ratings yet
Compute Assisment 2
11 pages
CSE202 Mini Project Report
PDF
No ratings yet
CSE202 Mini Project Report
13 pages
C lab 8
PDF
No ratings yet
C lab 8
4 pages
Labsheet#4
PDF
No ratings yet
Labsheet#4
11 pages
Phonebook
PDF
No ratings yet
Phonebook
10 pages
Demonstrate a program in C to create a data file named score
PDF
No ratings yet
Demonstrate a program in C to create a data file named score
3 pages
Aise Hi
PDF
No ratings yet
Aise Hi
11 pages
Module 5 Programs
PDF
No ratings yet
Module 5 Programs
8 pages
Adv C Slip Only Quesn
PDF
No ratings yet
Adv C Slip Only Quesn
12 pages
6.best Fit
PDF
No ratings yet
6.best Fit
9 pages
Assignment 11
PDF
No ratings yet
Assignment 11
4 pages
CD AND SS Lab (Lex)
PDF
No ratings yet
CD AND SS Lab (Lex)
16 pages
Structures in C
PDF
No ratings yet
Structures in C
6 pages
Fisiere Relative Structura
PDF
No ratings yet
Fisiere Relative Structura
3 pages
OS Lab
PDF
No ratings yet
OS Lab
19 pages
Bina
PDF
No ratings yet
Bina
12 pages
BST_LL_Pgm
PDF
No ratings yet
BST_LL_Pgm
2 pages
Code
PDF
No ratings yet
Code
5 pages
R51_P2
PDF
No ratings yet
R51_P2
4 pages
Program To Read File Containing Rollno, Name, Marks of Three Subjects and Calculate Total Marks, Result in Grade and Store in File
PDF
No ratings yet
Program To Read File Containing Rollno, Name, Marks of Three Subjects and Calculate Total Marks, Result in Grade and Store in File
9 pages
Assignment1 (Structure)
PDF
No ratings yet
Assignment1 (Structure)
10 pages
8
PDF
No ratings yet
8
2 pages
coding (1)
PDF
No ratings yet
coding (1)
30 pages
DSA
PDF
No ratings yet
DSA
17 pages
C Project Final Report
PDF
No ratings yet
C Project Final Report
13 pages
Prac 10
PDF
No ratings yet
Prac 10
11 pages
Subject: PRF192-PFC Workshop 07: Problem 1: Managing A List of Student Names
PDF
No ratings yet
Subject: PRF192-PFC Workshop 07: Problem 1: Managing A List of Student Names
17 pages
Include Include Include Include Include Struct Char Char Float Void Void Void Void Void Void Char Int Int Int Char
PDF
No ratings yet
Include Include Include Include Include Struct Char Char Float Void Void Void Void Void Void Char Int Int Int Char
6 pages
All Document Reader 1729225123806
PDF
No ratings yet
All Document Reader 1729225123806
69 pages
Real
PDF
No ratings yet
Real
3 pages
Gemini pop
PDF
No ratings yet
Gemini pop
27 pages
Turf Management System 1
PDF
100% (1)
Turf Management System 1
16 pages
C Lab
PDF
No ratings yet
C Lab
95 pages
Cdpractical
PDF
No ratings yet
Cdpractical
6 pages
Lms
PDF
No ratings yet
Lms
4 pages
Sa
PDF
No ratings yet
Sa
4 pages
File Handling utkrist
PDF
No ratings yet
File Handling utkrist
7 pages
DS Lab Program 7
PDF
No ratings yet
DS Lab Program 7
12 pages
Abs Loader
PDF
No ratings yet
Abs Loader
2 pages
Lab7 Os
PDF
No ratings yet
Lab7 Os
5 pages
DSA_smol
PDF
No ratings yet
DSA_smol
21 pages
CP Mid2
PDF
No ratings yet
CP Mid2
19 pages
Computer Engineering Laboratory Solution Primer
From Everand
Computer Engineering Laboratory Solution Primer
Karan Bhandari
No ratings yet
C programming Lab report
PDF
No ratings yet
C programming Lab report
28 pages
Algorithm and Programs
PDF
No ratings yet
Algorithm and Programs
25 pages
c file
PDF
No ratings yet
c file
120 pages
Al-Razi Guess Paper Computer Science (UM)
PDF
No ratings yet
Al-Razi Guess Paper Computer Science (UM)
4 pages
Model Answer Paper Summer 2018
PDF
No ratings yet
Model Answer Paper Summer 2018
24 pages
Unit 3 Notes Programming in C
PDF
No ratings yet
Unit 3 Notes Programming in C
46 pages
Bpops103 Module4
PDF
No ratings yet
Bpops103 Module4
47 pages
C Programs & Outputs
PDF
No ratings yet
C Programs & Outputs
15 pages
Some C programming problems and solutions for Civil Engineering C program course
PDF
No ratings yet
Some C programming problems and solutions for Civil Engineering C program course
39 pages
BCSL058 Solved Assignment 2024-25
PDF
No ratings yet
BCSL058 Solved Assignment 2024-25
41 pages
DAS Lab Programs2024
PDF
No ratings yet
DAS Lab Programs2024
55 pages
Structures_Session_5
PDF
No ratings yet
Structures_Session_5
2 pages
Unit-2 Control Statements
PDF
No ratings yet
Unit-2 Control Statements
33 pages
#Questions: 10 #Pages: 3 Set: A
PDF
No ratings yet
#Questions: 10 #Pages: 3 Set: A
13 pages
Module-2
PDF
No ratings yet
Module-2
106 pages
PPSC - Unit - 3
PDF
No ratings yet
PPSC - Unit - 3
21 pages
1
PDF
No ratings yet
1
19 pages
C Programming Lab Quiz - SOLUTION
PDF
No ratings yet
C Programming Lab Quiz - SOLUTION
4 pages
PSCP Notes Co3&Co4
PDF
No ratings yet
PSCP Notes Co3&Co4
58 pages
WEEK 1_240801095
PDF
No ratings yet
WEEK 1_240801095
14 pages
Os Lab Manual1
PDF
No ratings yet
Os Lab Manual1
49 pages
Os Lab Manual
PDF
No ratings yet
Os Lab Manual
81 pages
CP-LAB Record
PDF
No ratings yet
CP-LAB Record
65 pages
Chapter 10
PDF
No ratings yet
Chapter 10
37 pages
bcom-ca-ii-sem-material
PDF
No ratings yet
bcom-ca-ii-sem-material
75 pages
CODING QUESTIONS WITH ANSWERS
PDF
No ratings yet
CODING QUESTIONS WITH ANSWERS
8 pages
UNIT - IV-Function Msbet
PDF
No ratings yet
UNIT - IV-Function Msbet
24 pages
Data Structure Lab Manual
PDF
No ratings yet
Data Structure Lab Manual
91 pages
Csf101 Unit 03
PDF
No ratings yet
Csf101 Unit 03
53 pages
FinalElex Tec Ans
PDF
No ratings yet
FinalElex Tec Ans
8 pages
Related titles
Click to expand Related Titles
Carousel Previous
Carousel Next
Contact Management Project
PDF
Contact Management Project
Contact Management System in C - Javatpoint
PDF
Contact Management System in C - Javatpoint
text
PDF
text
Menudriven Filehandling
PDF
Menudriven Filehandling
Index SR No Topic Page No
PDF
Index SR No Topic Page No
Address Book Program in C
PDF
Address Book Program in C
Phone Book 2 Asign PRJ
PDF
Phone Book 2 Asign PRJ
Message (20)
PDF
Message (20)
Main 1
PDF
Main 1
BAKERY MANAGEMENT SYSTEM Project
PDF
BAKERY MANAGEMENT SYSTEM Project
Slips Sloution Advanced C
PDF
Slips Sloution Advanced C
DSLK
PDF
DSLK
Adv C Slip Solution
PDF
Adv C Slip Solution
Csprog 2 Workingna
PDF
Csprog 2 Workingna
coding (1) (1)
PDF
coding (1) (1)
OMKAR j3
PDF
OMKAR j3
Assignment - 5: #Include
PDF
Assignment - 5: #Include
Compute Assisment 2
PDF
Compute Assisment 2
CSE202 Mini Project Report
PDF
CSE202 Mini Project Report
C lab 8
PDF
C lab 8
Labsheet#4
PDF
Labsheet#4
Phonebook
PDF
Phonebook
Demonstrate a program in C to create a data file named score
PDF
Demonstrate a program in C to create a data file named score
Aise Hi
PDF
Aise Hi
Module 5 Programs
PDF
Module 5 Programs
Adv C Slip Only Quesn
PDF
Adv C Slip Only Quesn
6.best Fit
PDF
6.best Fit
Assignment 11
PDF
Assignment 11
CD AND SS Lab (Lex)
PDF
CD AND SS Lab (Lex)
Structures in C
PDF
Structures in C
Fisiere Relative Structura
PDF
Fisiere Relative Structura
OS Lab
PDF
OS Lab
Bina
PDF
Bina
BST_LL_Pgm
PDF
BST_LL_Pgm
Code
PDF
Code
R51_P2
PDF
R51_P2
Program To Read File Containing Rollno, Name, Marks of Three Subjects and Calculate Total Marks, Result in Grade and Store in File
PDF
Program To Read File Containing Rollno, Name, Marks of Three Subjects and Calculate Total Marks, Result in Grade and Store in File
Assignment1 (Structure)
PDF
Assignment1 (Structure)
8
PDF
8
coding (1)
PDF
coding (1)
DSA
PDF
DSA
C Project Final Report
PDF
C Project Final Report
Prac 10
PDF
Prac 10
Subject: PRF192-PFC Workshop 07: Problem 1: Managing A List of Student Names
PDF
Subject: PRF192-PFC Workshop 07: Problem 1: Managing A List of Student Names
Include Include Include Include Include Struct Char Char Float Void Void Void Void Void Void Char Int Int Int Char
PDF
Include Include Include Include Include Struct Char Char Float Void Void Void Void Void Void Char Int Int Int Char
All Document Reader 1729225123806
PDF
All Document Reader 1729225123806
Real
PDF
Real
Gemini pop
PDF
Gemini pop
Turf Management System 1
PDF
Turf Management System 1
C Lab
PDF
C Lab
Cdpractical
PDF
Cdpractical
Lms
PDF
Lms
Sa
PDF
Sa
File Handling utkrist
PDF
File Handling utkrist
DS Lab Program 7
PDF
DS Lab Program 7
Abs Loader
PDF
Abs Loader
Lab7 Os
PDF
Lab7 Os
DSA_smol
PDF
DSA_smol
CP Mid2
PDF
CP Mid2
Computer Engineering Laboratory Solution Primer
From Everand
Computer Engineering Laboratory Solution Primer
C programming Lab report
PDF
C programming Lab report
Algorithm and Programs
PDF
Algorithm and Programs
c file
PDF
c file
Al-Razi Guess Paper Computer Science (UM)
PDF
Al-Razi Guess Paper Computer Science (UM)
Model Answer Paper Summer 2018
PDF
Model Answer Paper Summer 2018
Unit 3 Notes Programming in C
PDF
Unit 3 Notes Programming in C
Bpops103 Module4
PDF
Bpops103 Module4
C Programs & Outputs
PDF
C Programs & Outputs
Some C programming problems and solutions for Civil Engineering C program course
PDF
Some C programming problems and solutions for Civil Engineering C program course
BCSL058 Solved Assignment 2024-25
PDF
BCSL058 Solved Assignment 2024-25
DAS Lab Programs2024
PDF
DAS Lab Programs2024
Structures_Session_5
PDF
Structures_Session_5
Unit-2 Control Statements
PDF
Unit-2 Control Statements
#Questions: 10 #Pages: 3 Set: A
PDF
#Questions: 10 #Pages: 3 Set: A
Module-2
PDF
Module-2
PPSC - Unit - 3
PDF
PPSC - Unit - 3
1
PDF
1
C Programming Lab Quiz - SOLUTION
PDF
C Programming Lab Quiz - SOLUTION
PSCP Notes Co3&Co4
PDF
PSCP Notes Co3&Co4
WEEK 1_240801095
PDF
WEEK 1_240801095
Os Lab Manual1
PDF
Os Lab Manual1
Os Lab Manual
PDF
Os Lab Manual
CP-LAB Record
PDF
CP-LAB Record
Chapter 10
PDF
Chapter 10
bcom-ca-ii-sem-material
PDF
bcom-ca-ii-sem-material
CODING QUESTIONS WITH ANSWERS
PDF
CODING QUESTIONS WITH ANSWERS
UNIT - IV-Function Msbet
PDF
UNIT - IV-Function Msbet
Data Structure Lab Manual
PDF
Data Structure Lab Manual
Csf101 Unit 03
PDF
Csf101 Unit 03
FinalElex Tec Ans
PDF
FinalElex Tec Ans