Programming Challenge Solution
#include <stdio.h>
char *program = "#include <stdio.h>%cchar *program = %c%s%c;%cint main()%c{%c
printf(program, 10, 34, program, 34, 10, 10, 10, 10, 10, 10);%c return 0;%c}%c";
int main()
{
printf(program, 10, 34, program, 34, 10, 10, 10, 10, 10, 10);
return 0;
}
The two key tricks here are using a string with an embedded %s specifier to
allow the string to contain itself when printed, and to use the
%c format specifier to allow printing out special characters like newlines,
which could not otherwise be embedded in the output string.
Download source |