C Program to Write n Persons Details in Data File and Display

0
3
digitalample eye
Write a C program to write ‘n’ persons name, address, and telco in a data file and display them, reading the successive data from the file in proper format.

C Program to write n persons name, address, and telephone number in a data file and display them reading the successive data from the file in proper format.

Source Code,

#include <stdio.h>
#include <conio.h>
void main()
{
char name[25];
char address[25];
char telno[25];
FILE *fp;
int i,n;
clrscr();
fp=fopen("rec.data","a");
printf("Enter how many records:");
scanf("%d",&n);
for(i=0;i<n;i++)
{
printf("nEnter the name:");
scanf("%s",name);
printf("nEnter the address:");
scanf("%s",address);
printf("nEnter the telno:");
scanf("%s",telno);
fprintf(fp,"n%st%st%s",name,address,telno);
}
fclose(fp);
fp=fopen("rec.data","r");
printf("NametAddresstttTelnon");
while(fscanf(fp,"%s%s%s",name,address,telno)!=EOF)
{
printf("n%st%st%s",name,address,telno);
}
fclose(fp);
getch();
}

LEAVE A REPLY

Please enter your comment!
Please enter your name here