Can you write a program that prints its own source code ( in C/C++ )? Of course it would be easy to do that referring to the source file, but how can this program be written assuming that the souce file is not available at run time?
:?: :?:

It can't.

An old one..

Hope this is what u looking for

char*s="char*s=%c%s%c;main(){printf(s,34,s,34);}";
main()
{
  printf(s,34,s,34);
}

These are called signature programs by the way..

And if you compile a program in a compiler's debug mode, it compiles the source code into the resulting executable file. I assume using some process in the program, you would be able to extract the source code (although I could be wrong).

[edit] My 1000th post

It can't.

It's proven that in any Turing-complete language you can create a program that writes its own code as output.

commented: Yup +3
Member Avatar for iamthwee

It's proven that in any Turing-complete language you can create a program that writes its own code as output.

Yeah. My guess is Mr Disney was trying to be smart... should have googled first before making assumptions. Ha ha.

commented: :( -2

Here's another one Link

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.