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
What is the use of the function in c?
#include
What is structure in c explain with example?
What is meant by int main ()?
find the value of y y = 1.5x+3 for x<=2 y = 2x+5 for x>2
Which header file is used for clrscr?
What is the difference between procedural and functional programming?
write a program to copy the string using switch case?
Which is an example of a structural homology?
What are the 5 types of inheritance in c ++?
How are variables declared in c?
Difference between constant pointer and pointer to a constant.
Write a program to know whether the input number is an armstrong number.
Is Exception handling possible in c language?
What should malloc() do? Return a null pointer or a pointer to 0 bytes?