Jul 28, 2006

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

No comments:

About Me

My photo
This web site recorded something interesting about free software, photographics, music, other stuff and a little tic.

My new website location in www.kuangxuqing.com