A C Program To Read Formatted Data From A File

26 March 20120 comments

The following program reads the formatted data from the file.
  1. #include<stdio.h>
  2. #include<conio.h>
  3. void main()
  4. {
  5.      FILE *fp;
  6.      char name[20];
  7.      int age;
  8.      float salary;
  9.      clrscr();
  10.      if((fp==fopen("text1.dat","r"))==NULL)
  11.      {
  12.          printf("\n Can not open file");
  13.          exit(1);
  14.      }
  15.      while(fscanf(fp,"%s%d%f",name,&age,&salary)!=EOF)
  16.         printf("%s\t%d\t%f\n",name,age,salary);
  17.      fclose(fp);
  18.      getch();
  19. }
tags: C programming Examples , File handling programs in C , Programming Examples on Files in C , Program to read formatted data from a file in C
Share this article :

Post a Comment

 
Copyright © 2011. All Compiler - All Rights Reserved