Q23 Write a C program which produces its own source code as its output.

#include<stdio.h>

int main()

{

FILE *fptr;

char chr;

fptr = fopen(__FILE__,”r”);

do{

chr= getc(fptr);

putchar(chr);

}

while(chr!=EOF);

fclose(fptr);

return 0;

}

Output:

$ ./a.exe

#include<stdio.h>

int main()

{

FILE *fptr;

char chr;

fptr = fopen(__FILE__,”r”);

do{

chr= getc(fptr);

putchar(chr);

}

while(chr!=EOF);

fclose(fptr);

return 0;

}

Leave a Reply

Your email address will not be published.

This site uses Akismet to reduce spam. Learn how your comment data is processed.