C Programming
Computer Programming

C file handling program to read Content of a File using getc() function



Write C file handling program to read Content of a File using getc() function

\* C file handling program to read Content of a File using getc() function *\

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

char filename[20];
FILE *fp ;
char ch ;
printf("\n Enter the filename to be opened : ") ;
scanf("%s", filename) ;
fp = fopen(filename, "r") ;
if (fp == NULL)
{
      printf(" Cannot open file ! \n") ;
      exit(0) ;
}

printf("\n Content of file : \n") ;
while( (ch=getc(fp))!=EOF )
{
      printf("%c", ch ) ;
}
fclose(fp) ;
return 0 ;

}

Output of Program :

Output of C file handling program to read Content of a File using getc() function