May 25, 2008

Self Printing C Code

Have you ever tried writing a C code that prints the source itself. Its a little bit tricky anyway. But the solution is here
#include
char *program = “#include %c char *program = %c%s%c;%c int main()%c{%cprintf(program, 10, 34, program, 34, 10, 10, 10, 10, 10, 10);%c return 0;%c}%c”;
int main()
{
[...]