Breaking News

How to Display A program's own Source Code as Output in C programming Language

Though you may think that is  problem is quite complex but actually ,the concept behind this program is very simple.

A predefined macro __FILE__ contains the location of a C programming file.we will be using this macro in our program.

Source Code-


 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
#include <stdio.h>
int main() {
    FILE *fp;
    char c;
    fp = fopen(__FILE__,"r");
    do {
         c = getc(fp);
         putchar(c);
    }
    while(c != EOF);
    fclose(fp);
    return 0;
}

Output-


No comments

shankhajana. Powered by Blogger.