Private archive copy · Unofficial site · Content copyright belongs to Runoob Tutorial and the original authors · View Original

C Language Examples - Output the Code of the Current File

C Language Examples - Output the Code of the Current File

C Language Examples C Language Examples

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 C Language Examples