0

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?
:?: :?:

8
Contributors
7
Replies
9
Views
10 Years
Discussion Span
Last Post by SpS
0

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..

0

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

1

It can't.

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

Votes + Comments
Yup
-2

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.

Votes + Comments
:(
This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.