Spread the love

Question :- C Program to Display its own Source Code as its Output

Here is source code of the C Program to display its own source code as its output. We have used low-level file handling to achieve this.

/* C Program to Display its own Source Code as its Output */
#include <stdio.h>
 
int main()
{
    FILE *fp;
    char ch;
 
    fp = fopen(__FILE__,"r");
   
    while (ch != EOF)
    {
        ch = getc(fp);
        putchar(ch);
    }
    
	fclose(fp);
 
    return 0;
}