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

How do you determine the length of a string value that was stored in a variable?

647


Write a program to show the change in position of a cursor using c

575


What is #include in c?

596


What are the basic data types associated with c?

811


What is operator promotion?

624






What is a structure in c language. how to initialise a structure in c?

603


how logic is used

1493


How can I use a preprocessorif expression to ?

596


How can I get the current date or time of day in a c program?

647


Why is struct padding needed?

625


Find MAXIMUM of three distinct integers using a single C statement

622


What is a floating point in c?

598


What is the difference between char array and char pointer?

525


How do I use void main?

629


List the difference between a "copy constructor" and a "assignment operator"?

576