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

Answer Posted / yogesh bansal

#include <stdio.h>

int main()
{
FILE *file;
char filename[]="outputsourcecode.c";
char str[125];
file=fopen(filename,"r");
if(file == NULL)
{
printf("cannot open the file");
exit(1);
}
while(!feof(file))
{
if(fgets(str,125,file))
{
printf("%s", str);
}
}
return 0;
}

this is a working code.

Is This Answer Correct ?    4 Yes 0 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

What is header file in c?

825


What are dangling pointers in c?

827


Explain what is the difference between a free-standing and a hosted environment?

882


What is huge pointer in c?

758


What is a stream in c programming?

812


Explain what are reserved words?

834


What is a volatile keyword in c?

883


By using C language input a date into it and if it is right?

795


What is the use of a static variable in c?

776


What is the c value paradox and how is it explained?

781


Why n++ execute faster than n+1 ?

2295


Is null equal to 0 in sql?

861


What is a 'null pointer assignment' error?

934


What is main function in c?

766


Are enumerations really portable?

787