printf self

Below C code will print the source code itself.

#include

char buf[100][1000]; int cur=-1;

void P1(char *p) {sprintf(buf[ cur],p);} //record p to buf
void P2(char *p) { printf(p); putchar(10);} //print p and change line
void P3() {int i;for(i=0;i");
P1("char buf[100][1000]; int cur=-1;");
P1("void P1(char *p) {sprintf(buf[ cur],p);}");
P1("void P2(char *p) { printf(p); putchar(10);}");
P1("void P3() {int i;for(i=0;i");
P2("char buf[100][1000]; int cur=-1;");
P2("void P1(char *p) {sprintf(buf[ cur],p);}");
P2("void P2(char *p) { printf(p); putchar(10);}");
P2("void P3() {int i;for(i=0;i

Technorati Tags: , , ,

Posted by K*K Sat, 29 Jul 2006 14:40:00 +0800