尽管这个问题看起来很复杂,但这个程序的根本概念很简单;显示来自你编写源代码的同一文件中的内容。

在C编程中,有一个名为__FILE__
的预定义宏,它给出了当前输入文件的名称。
#include <stdio.h> int main() { // location the current input file. printf("%s",__FILE__); }
C程序显示自己的源代码
#include <stdio.h>
int main() {
FILE *fp;
int c;
// open the current input file
fp = fopen(__FILE__,"r");
do {
c = getc(fp); // read character
putchar(c); // display character
}
while(c != EOF); // loop until the end of file is reached
fclose(fp);
return 0;
}