0% found this document useful (0 votes)
44 views1 page

File Handling

The document describes a C program that defines a structure for storing telephone contact information with name and number fields. It prompts the user to input details for m contacts, writes this data to a binary file "tele.dat", and provides modifications to access this file to search for a contact's number by name or name by number.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as ODT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
44 views1 page

File Handling

The document describes a C program that defines a structure for storing telephone contact information with name and number fields. It prompts the user to input details for m contacts, writes this data to a binary file "tele.dat", and provides modifications to access this file to search for a contact's number by name or name by number.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as ODT, PDF, TXT or read online on Scribd
You are on page 1/ 1

File Handling

Sample Program
#define m 3
struct telephone
{
char name[30];
long number;
};
main( )
{
int i;
struct telephone person[m];
FILE *fp;
for (i=0;i<m;i++)
{
printf(“Enter the information of person %d:”,i);
scanf(“%s %ld”,person[i].name,&person[i].number);
}
fp = fopen(“tele.dat”,”w”);
for(i=0;i<m;i++)
fprintf(fp,”%-20s %10ld\n”,person[i].name,person[i].number);
fclose(fp);
}

Modification:

1. Modify the above program such that it will access the data file created in the above
program and perform the following tasks.
 Display telephone number of a particular customer identified by the name.
 Display name of a particular customer identified by the telephone number.

You might also like