Inadvertently saw such a problem:
Choose a language to write a program that prints its own source code, which does not allow you to read or write data from other files, and the program must be completely independent.
It's funny. I am learning C language, this problem is I look for other information to see, this aroused my interest, I lay in bed for a long time, no clue, forehead, finally hold the thought is unlikely to realize the idea fell asleep.
Back to the point, I searched the information on the Internet, I know how to write a program, the principle is to define a string of the source code itself, and then add a string to rewrite the program itself to encode the algorithm, the last output string. Because the C language has a printf (), it is very convenient to implement this code, because I do not have other languages, so just put the code C: #include <stdio.h>
int main ()
{
Char *s = "#include <stdio.h>%cint main () {char *s =%c%s%c; printf (s, N, S, 34); return 0; }";
printf (s, N, S, 34); return 0;
}
One thing to keep in mind is that this code should have a way of indicating the location of the print and how much to print.