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
Why is not a pointer null after calling free?
how many types of operators are include in c language a) 4 b) 6 c) 8 d) 12
How do we open a binary file in Read/Write mode in C?
Define Spanning-Tree Protocol (STP)
What is n in c?
How can you find the exact size of a data type in c?
What is typedef struct in c?
How is = symbol different from == symbol in c programming?
What is the difference between text and binary modes?
What is the purpose of 'register' keyword in c language?
What are the types of data structures in c?
Is c language still used?
What is #include stdlib h?
What is variable initialization and why is it important?
Write a program to swap two numbers without using third variable?