How do you write a program which produces its own source
code as its output?

Answer Posted / vivek

printitself.c

#include <stdio.h>

int main()
{

char ch;
FILE *file;

file=fopen("printitself.c","r");

while((ch=fgetc(file))!=EOF)
printf("%c",ch);

return 0;
}

Is This Answer Correct ?    19 Yes 2 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

Why do we use int main instead of void main in c?

611


Why header file is used in c?

571


Is it fine to write void main () or main () in c?

541


Write a program to reverse a given number in c?

593


What is wild pointer in c with example?

569






What is malloc return c?

596


What is %g in c?

611


Why doesn't C support function overloading?

1607


What is the use of clrscr?

589


What is function definition in c?

582


What is maximum size of array in c?

580


Explain what is the difference between null and nul?

648


Is using exit() the same as using return?

669


Is null valid for pointers to functions?

604


Are there any problems with performing mathematical operations on different variable types?

568