Read data from file by format - C File

C examples for File:Binary File

Description

Read data from file by format

Demo Code

#include <stdio.h> 
int main()/*from w  w w  . j  a va2 s. co m*/
{ 
   FILE *pRead; 
   char fName[20]; 
   char lName[20]; 
   char id[15]; 
   float gpa; 
   pRead = fopen("students.dat", "r"); 
  
   if ( pRead == NULL ) 
      printf("\nFile not opened\n"); 
   else { 
      printf("\nName\t\tID\t\tGPA\n\n"); 

      fscanf(pRead, "%s%s%s%f", fName, lName, id, &gpa); 

      printf("%s %s\t%s\t%.2f\n", fName, lName, id, gpa); 
      fclose(pRead); 
   }
}

Result


Related Tutorials