Reading Data from a file - C File

C examples for File:Binary File

Description

Reading Data from a file

Demo Code

#include <stdio.h> 
int main() /*from   w w  w .ja v a  2  s. c o m*/
{ 
   FILE *pRead; 
   char name[10]; 
   pRead = fopen("names.dat", "r"); 
   if ( pRead == NULL ) 
      printf("\nFile cannot be opened\n"); 
   else 
      printf("\nContents of names.dat\n\n"); 
   fscanf(pRead, "%s", name); 
   while ( !feof(pRead) ) { 
         printf("%s\n", name); 
         fscanf(pRead, "%s", name); 
   }
}

Result


Related Tutorials