C Program to Display its own Source Code as Output

C Program to Display its own Source Code as Output

#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;
}

c c c c c c c c c c c c c c c c c c c c c c c c c c c c c c c c c c c c program program program program program program program program program program program c language c language c language c language c language c language c language

Comments