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

C Program to Write n Persons Details in Data File and Display, Write a C program to write ‘n’ persons name, address and telno in a data file and display them, reading the successive data from the file in proper format.

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%s\t%s\t%s",name,address,telno);
 }
 fclose(fp);
 fp=fopen("rec.data","r");
 printf("Name\tAddress\t\t\tTelno\n");
 while(fscanf(fp,"%s%s%s",name,address,telno)!=EOF)
 {
  printf("\n%s\t%s\t%s",name,address,telno);
 }
 fclose(fp);
 getch();
}

You May Also Like...

Socialize with Us