C Language Examples - Output the Code of the Current File
Output the code of the currently executing file,FILE is a constant for the currently executing file.
Example
#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
;
}
The output is:
#include
int main() {
FILE *fp;
char c;
fp = fopen(__FILE__,"r");
do {
c = getc(fp);
putchar(c);
}
while(c != EOF);
fclose(fp);
return 0;
}
C Language Examples