Sunday, November 20, 2016

How to Display A programs own Source Code as Output in C programming Language

How to Display A programs 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-



Available link for download