Access Millions of academic & study documents

Phone book c language

Content type
User Generated
Showing Page:
1/7
Project Title : Phone Book
I. C Coding:
#include<stdio.h>
#include<string.h>
struct PhBook
{
char name[26];
char num[11];
}pb[1000];
void add(struct PhBook *ptr)//Function to add a number
{
FILE *fp;
int i,n;
fp=fopen("phbook.dat","wb");
printf("\nEnter no of records: ");
scanf("%d",&n);
for (i=0;i<n;i++)
{
printf("\nEnter Name: ");
scanf("%s",&ptr->name);
printf("\nEnter phone number: ");
scanf("%s",&ptr->num);
printf("\nSucessfully added\n");
fwrite(&pb,sizeof(pb),1,fp);//syntax for writing to binary file fwrite()
ptr++;
}

Sign up to view the full document!

lock_open Sign Up
Showing Page:
2/7
fclose(fp);
}
void search(struct PhBook *ptr)//Function to display
{
FILE *fp;
fp=fopen("phbook.dat","rb");
char x[25];
int flag=0,i;
printf("\nEnter name to be searched: ");
scanf("%s",&x);
while(fread(&pb,sizeof(pb),1,fp)==1)
{
if (strcmpi(ptr->name,x)==0)
{
printf("\n%s: ",ptr->name);
printf("%s",ptr->num);
flag=1;
}
ptr++;
}
if (flag==0)
{
printf("\nNo number found");
}
printf("\n***************************************************************************\n");
printf("\n");
fclose(fp);
}
void display(struct PhBook *ptr)//Function to display
{
FILE *fp;
fp=fopen("phbook.dat","rb");
int i;
while(fread(&pb,sizeof(pb),1,fp)==1)
{
printf("\n%s: +91%s \n",ptr->name,ptr->num);
ptr++;
}

Sign up to view the full document!

lock_open Sign Up
Showing Page:
3/7

Sign up to view the full document!

lock_open Sign Up
Showing Page:
4/7

Sign up to view the full document!

lock_open Sign Up
End of Preview - Want to read all 7 pages?
Access Now
Unformatted Attachment Preview
Project Title : Phone Book I. C Coding: #include #include struct PhBook { char name[26]; char num[11]; }pb[1000]; void add(struct PhBook *ptr)//Function to add a number { FILE *fp; int i,n; fp=fopen("phbook.dat","wb"); printf("\nEnter no of records: "); scanf("%d",&n); for (i=0;iname); printf("\nEnter phone number: "); scanf("%s",&ptr->num); printf("\nSucessfully added\n"); fwrite(&pb,sizeof(pb),1,fp);//syntax for writing to binary file fwrite() ptr++; } fclose(fp); } void search(struct PhBook *ptr)//Function to display { FILE *fp; fp=fopen("phbook.dat","rb"); char x[25]; int flag=0,i; printf("\nEnter name to be searched: "); scanf("%s",&x); while(fread(&pb,sizeof(pb),1,fp)==1) { if (strcmpi(ptr->name,x)==0) { printf("\n%s: ",ptr->name); printf("%s",ptr->num); flag=1; } ptr++; } if (flag==0) { printf("\nNo number found"); } printf("\n***************************************************************************\n"); printf("\n"); fclose(fp); } void display(struct PhBook *ptr)//Function to display { FILE *fp; fp=fopen("phbook.dat","rb"); int i; while(fread(&pb,sizeof(pb),1,fp)==1) { printf("\n%s: +91%s \n",ptr->name,ptr->num); ptr++; } printf("\n"); fclose(fp); } void main() { int ch=0,ct=0,i; printf("\n ====================================================================== ====\n"); printf("\t\t\t\t PH0NE B00K "); printf("\n ====================================================================== ====\n") ...
Purchase document to see full attachment
User generated content is uploaded by users for the purposes of learning and should be used following Studypool's honor code & terms of service.
Studypool
4.7
Indeed
4.5
Sitejabber
4.4