You are on page 1of 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