C Programming
Computer Programming

C file handling program to Illustrate Reading of Data from a File



Write C file handling program to Illustrate Reading of Data from a File

\* C file handling program to Illustrate Reading of Data from a File *\

# include < stdio.h >
# include < stdlib.h >
int   main( )
{

FILE *fptr ;
char filename[15] ;
char ch ;
printf("\n Enter the filename to be opened : ") ;
scanf("%s", filename ) ;

/* open the file for reading */
fptr = fopen(filename, "r") ;
if (fptr == NULL)
{
      printf(" Cannot open file ! \n") ;
      exit(0);
}
ch = fgetc(fptr) ;
while (ch != EOF)
{
      printf ("%c", ch ) ;
      ch = fgetc(fptr) ;
}
fclose(fptr) ;
return 0 ;

}

Output of Program :

Output of C file handling program to Illustrate Reading of Data from a File