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
How do you determine the length of a string value that was stored in a variable?
Write a program to show the change in position of a cursor using c
What is #include in c?
What are the basic data types associated with c?
What is operator promotion?
What is a structure in c language. how to initialise a structure in c?
how logic is used
How can I use a preprocessorif expression to ?
How can I get the current date or time of day in a c program?
Why is struct padding needed?
Find MAXIMUM of three distinct integers using a single C statement
What is a floating point in c?
What is the difference between char array and char pointer?
How do I use void main?
List the difference between a "copy constructor" and a "assignment operator"?