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 assignment operator?

620


can we have joblib in a proc ?

1650


in multiple branching construct "default" case is a) optional b) compulsarily c) it is not include in this construct d) none of the above

629


How do we open a binary file in Read/Write mode in C?

674


What are the 5 types of organizational structures?

546






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

638


Can you please explain the difference between strcpy() and memcpy() function?

593


What is the use of define in c?

590


Write a code to generate divisors of an integer?

630


Is it better to use a macro or a function?

647


What is the process to generate random numbers in c programming language?

604


How can I prevent another program from modifying part of a file that I am modifying?

606


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

2717


What is structure pointer in c?

565


What are the different types of errors?

635