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 assignment operator?
can we have joblib in a proc ?
in multiple branching construct "default" case is a) optional b) compulsarily c) it is not include in this construct d) none of the above
How do we open a binary file in Read/Write mode in C?
What are the 5 types of organizational structures?
A text file that contains declarations used by a group of functions,programs,or users a) executable file b) header file c) obj file d) .cfile
Can you please explain the difference between strcpy() and memcpy() function?
What is the use of define in c?
Write a code to generate divisors of an integer?
Is it better to use a macro or a function?
What is the process to generate random numbers in c programming language?
How can I prevent another program from modifying part of a file that I am modifying?
how to print electricity bill according to following charges first 100 units -1rs per unit for next 200 units-1.50 rs per unit without using conditions
What is structure pointer in c?
What are the different types of errors?