C program to display same source code as output

C program to display same source code as output:
If you are using any software then below program will not give an error, but if you are using TURBO C then you have to make some changes like: void main() and some function like clrscr() or getch().

#include<stdio.h>

main()
{
   FILE *f;
   char ch;

   f=fopen(__FILE__,"r");

   do
   {
      ch=getc(f);
      putchar(ch);
   }while(ch != EOF);

   fclose(f);
}

OUTPUT:

#include<stdio.h>

main()
{
   FILE *f;
   char ch;

   f=fopen(__FILE__,"r");

   do
   {
      ch=getc(f);
      putchar(ch);
   }while(ch != EOF);

   fclose(f);
}

 

You may also like...

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.