Search This Blog

Tuesday, 31 October 2017

Display content of file : C Program

/*Basic file handling programs.
    Display content of file. */

#include<stdio.h>
#include<conio.h>

void main()
{
 FILE *fp;
 char ch;
 clrscr();
 fp=fopen("ajay.txt","r");

 if(fp==NULL)
 {
  printf("Error occured while opening file");
 }
 else
 {
  printf("\n***************** File Content *****************\n");
  while(1)
  {
   ch=getc(fp);
   if(ch==EOF)
   {
    break;
   }
   printf("%c",ch);
  }
  printf("\n************* End of  File Content **************\n");
 }
 fclose(fp);
 getch();
}


Output Screens :

No comments:

Post a Comment