The problem seems complicated but the concept behind it is very simple;
display the content from the same file you are writing the source code.
A predefined
macro __FILE__ contains the location of the programming file, it is working on.
For example: the output of following programs display the location of their files.
#include
<stdio.h>
int main() {
printf("%s",__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);
putchar(c);
}
while(c !=
EOF);
fclose(fp);
return 0;
}