There are So many complex methods for that but i write the most effective and simple one just write this ..
// program name avi.c
#include<stdlib.h>
void main()
{ //// write ur program logic here
getch();
system("type avi.c");
}
by the use of this system function from stdlib.h u can run any dos command from ur c program but please check the output for this only by running the exe of ur program ( in this case avi.exe)
RE: How do you write a program which produces its own source code as its output?
/* Program to printf itself on console */ #include int main(void) { FILE *in; clrscr(); if ((in fopen( 8.c r )) NULL) { printf( Cannot open input file.n ); return 1; } while (!feof(in)) printf( c fgetc(in)); fclose(in); getche(); return 0; }
RE: How do you write a program which produces its own ...
Hi
There are So many complex methods for that but i write the most effective and simple one just write this ..
// program name avi.c
#include<stdlib.h>
void main()
{ //// write ur program logic here
getch();
system( type avi.c );
}
by the use of this system function from stdlib.h u can run any dos command from ur c program but please check the output for this only by running the exe of ur program ( in this case avi.exe)
RE: How do you write a program which produces its own ...
All the solutions above are reading the source code with the files concepts.
find a solution where you do not have a source file to read the contents.
There is a macro or an attiribute which tells the compiler the name of the program function or the attribute. You can use that to get the source code. try out...!!!