/*…Hey Guy’s This Is A Program In C For Making A Telephone Directory System…*/
#include <stdio.h>
#include <conio.h>
#include <string.h>
#include<stdlib.h>
/*…Defining Structure…*/
struct person
{
char pname[20];
long tel_no;
};
{
char pname[20];
long tel_no;
};
/*…Function For Adding New Record …*/
void Add_Record()
{
FILE *fp;
struct person obj;
clrscr();
fp=fopen(“data.txt”,”a”); /*….Open A File Name “Data.txt” And Perforn Append On It..*/
printf(“*****Add Record****\n”);
printf(“Enter Name : “);
scanf(“%s”,obj.pname);
printf(“Enter Telephone No. : “);
scanf(“%ld”,&obj.tel_no);
fprintf(fp,”%20s %7ld”,obj.pname,obj.tel_no);
fclose(fp); /*….Close The File…*/
}
FILE *fp;
struct person obj;
clrscr();
fp=fopen(“data.txt”,”a”); /*….Open A File Name “Data.txt” And Perforn Append On It..*/
printf(“*****Add Record****\n”);
printf(“Enter Name : “);
scanf(“%s”,obj.pname);
printf(“Enter Telephone No. : “);
scanf(“%ld”,&obj.tel_no);
fprintf(fp,”%20s %7ld”,obj.pname,obj.tel_no);
fclose(fp); /*….Close The File…*/
}
/*…Function For Showing All Records..*/
void showAll_Record()
{
FILE *fp;
struct person obj;
clrscr();
fp=fopen(“data.txt”,”r”); /*…Read The File “Data.txt”…*/
printf(“*****Display All Records*****\n”);
printf(“\n\n\t\tName\t\t\tTelephone No.”);
printf(“\n\t\t=====\t\t\t===============\n\n”);
while(!feof(fp))
{
fscanf(fp,”%20s %7ld”,obj.pname,&obj.tel_no);
printf(“%20s %30ld\n”,obj.pname,obj.tel_no);
}
fclose(fp);
getch();
}
{
FILE *fp;
struct person obj;
clrscr();
fp=fopen(“data.txt”,”r”); /*…Read The File “Data.txt”…*/
printf(“*****Display All Records*****\n”);
printf(“\n\n\t\tName\t\t\tTelephone No.”);
printf(“\n\t\t=====\t\t\t===============\n\n”);
while(!feof(fp))
{
fscanf(fp,”%20s %7ld”,obj.pname,&obj.tel_no);
printf(“%20s %30ld\n”,obj.pname,obj.tel_no);
}
fclose(fp);
getch();
}
/*…Function For Finding Records…*/
void find_Record()
{
FILE *fp;
struct person obj;
char pname[20];
int totalrec=0;
clrscr();
fp=fopen(“data.txt”,”r”); /*…Read The File “Data.txt”..*/
printf(“*****Display Specific Records*****\n”);
printf(“\nEnter Name : “);
scanf(“%s”,&pname);
while(!feof(fp))
{
fscanf(fp,”%20s %7ld”,obj.pname,&obj.tel_no);
if(strcmpi(obj.pname,pname)==0)
{
printf(“\n\nName : %s”,obj.pname);
printf(“\nTelephone No : %ld”,obj.tel_no);
totalrec++;
}
}
if(totalrec==0)
printf(“\n\n\nNo Data Found”);
else
printf(“\n\n===Total %d Record found===”,totalrec);
fclose(fp);
getch();
}
{
FILE *fp;
struct person obj;
char pname[20];
int totalrec=0;
clrscr();
fp=fopen(“data.txt”,”r”); /*…Read The File “Data.txt”..*/
printf(“*****Display Specific Records*****\n”);
printf(“\nEnter Name : “);
scanf(“%s”,&pname);
while(!feof(fp))
{
fscanf(fp,”%20s %7ld”,obj.pname,&obj.tel_no);
if(strcmpi(obj.pname,pname)==0)
{
printf(“\n\nName : %s”,obj.pname);
printf(“\nTelephone No : %ld”,obj.tel_no);
totalrec++;
}
}
if(totalrec==0)
printf(“\n\n\nNo Data Found”);
else
printf(“\n\n===Total %d Record found===”,totalrec);
fclose(fp);
getch();
}
/*…Main Function Start’s…*/
void main()
{
char ch;
while(1)
{
clrscr();
printf(“*****TELEPHONE DIRECTORY*****\n\n”);
printf(“1) Add New Record\n”);
printf(“2) Find Record\n”);
printf(“3) Read All record\n”);
printf(“4) exit\n”);
printf(“Enter your choice : “);
fflush(stdin);
ch = getche();
switch(ch)
{
case’1′ : //call append record
Add_Record();
break;
case’2′ : //call find record
find_Record();
break;
case’3′ : //Read all record
showAll_Record();
break;
case’4′ :
case 27 : exit(1);
}
}
}
{
char ch;
while(1)
{
clrscr();
printf(“*****TELEPHONE DIRECTORY*****\n\n”);
printf(“1) Add New Record\n”);
printf(“2) Find Record\n”);
printf(“3) Read All record\n”);
printf(“4) exit\n”);
printf(“Enter your choice : “);
fflush(stdin);
ch = getche();
switch(ch)
{
case’1′ : //call append record
Add_Record();
break;
case’2′ : //call find record
find_Record();
break;
case’3′ : //Read all record
showAll_Record();
break;
case’4′ :
case 27 : exit(1);
}
}
}
/*…Main Function End’s…*/
OUTPUT
No comments:
Post a Comment