fastread homefastrread library fastread menu

C : Display its own Source Code as Output

Tutorial by:Manisha Dubey      Date: 2016-06-17 04:46:12

❰ Previous Next ❱

Though this problem seems complex but, the concept behind this program is very simple; display the content from the same file you are writing the source code.


A predefined macro __FILE__ contains the location of a C programming file, it is working on. For example:

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



The output of this program is the location of this C programming file.

C program to display its own source code using __FILE__

#include <stdio.h>
int main() {
    FILE *fp;
    char c;
    fp = fopen(__FILE__,"r");
    do {
         c = getc(fp);
    while(c != EOF);
    return 0;

This program displays the content of this particular C programming file(source code) because __FILE__ contains the location of this C programming file in a string.

❰ Previous Next ❱


Submit Your Thought, Tutorial, Articls etc.

Submit Your Information India's Number one online promotion website