|
C
For Swimmers : Mastering C step-by-step |
|
|
NOTE : It is assumed
that -
Necessary header files are included
Programs/Snippets are tested under Linux as well as
Windows platform
Programs/Snippets
are compiled using VC++ 6.0 as well as gcc 3.2
The underlying machine is an x86 system
Crazy
Coding : Self Reproducible Programs
Self-reproducible
programs - programs
that produce their own source code. I included an
interesting collection
of self-reproducing code in C programming language. Few of
them might generate warnings but should compile fine.
Source
: Obfuscated C Code contest - www.ioccc.org
Note:
This page can be best viewed with IE 6.0 or above.
|
| [Q001] Self-reproducible C code : |
| main(){char*p="main(){char*p=%c%s%c;(void)printf(p,34,p,34,10);}%c";(void)printf(p,34,p,34,10);}
|
| OUTPUT: Same
as the actual source code.
main(){char*p="main(){char*p=%c%s%c;(void)printf(p,34,p,34,10);}%c";(void)printf(p,34,p,34,10);}
|
|
|
| [Q002] Self-reproducible C code
: |
|
main(a){a="main(a){a=%c%s%c;printf(a,34,a,34);}";printf(a,34,a,34);}
|
| OUTPUT: Same as the
actual source code.
main(a){a="main(a){a=%c%s%c;printf(a,34,a,34);}";printf(a,34,a,34);}
|
|
|
| [Q003] Self-reproducible C code
: |
|
main(){char*a="main(){char*a=%c%s%c;int
b='%c';printf(a,b,a,b,b);}";int b='"';printf(a,b,a,b,b);}
|
| OUTPUT: Same as the
actual source code.
main(){char*a="main(){char*a=%c%s%c;int b='%c';printf(a,b,a,b,b);}";int b='"';printf(a,b,a,b,b);}
|
|
|
| [Q004] Self-reproducible C code
: |
|
main(a){printf(a,34,a="main(a){printf(a,34,a=%c%s%c,34);}",34);}
|
| OUTPUT: Same as the
actual source code.
main(a){printf(a,34,a="main(a){printf(a,34,a=%c%s%c,34);}",34);}
|
|
|
| [Q005] Self-reproducible C code
: |
|
main(){char *c="main(){char *c=%c%s%c;printf(c,34,c,34);}";printf(c,34,c,34);}
|
| OUTPUT: Same as the
actual source code.
main(){char *c="main(){char *c=%c%s%c;printf(c,34,c,34);}";printf(c,34,c,34);}
|
|
|
| [Q006] Self-reproducible C code
: |
|
main(){char*c="\\\"#include<stdio.h>%cmain(){char*c=%c%c%c%.102s%cn%c;printf(c+2,c[102],c[1],*c,*c,c,*c,c[1]);exit(0);}\n";printf(c+2,c[102],c[1],*c,*c,c,*c,c[1]);exit(0);}
|
| OUTPUT: Same as the
actual source code.
main(){char*c="\\\"#include<stdio.h>%cmain(){char*c=%c%c%c%.102s%cn%c;printf(c+2,c[102],c[1],*c,*c,c,*c,c[1]);exit(0);}\n";printf(c+2,c[102],c[1],*c,*c,c,*c,c[1]);exit(0);}
|
|
|
| [Q007] Self-reproducible C code
: |
|
p="p=%c%s%c;main(){printf(p,34,p,34);}";main(){printf(p,34,p,34);}
|
| OUTPUT: Same as the
actual source code.
p="p=%c%s%c;main(){printf(p,34,p,34);}";main(){printf(p,34,p,34);}
|
|
|
| [Q008] Self-reproducible C code
: |
|
#define T(a) main(){printf(a,#a);}
T("#define T(a) main(){printf(a,#a);}\nT(%s)")
|
| OUTPUT: Same as the
actual source code.
#define T(a) main(){printf(a,#a);}
T("#define T(a) main(){printf(a,#a);}\nT(%s)")
|
|
|
| [Q009] Self-reproducible C code as well as palindrome : |
|
/**/char q='"',*a="*//**/char q='%c',*a=%c%s%c*/};)b(stup;]d[b=]d-852[b)--d(elihw;)q,a,q,q,2+a,b(ftnirps{)(niam;031=d
tni;]952[b,",b[259];int
d=130;main(){sprintf(b,a+2,q,q,a,q);while(d--)b[258-d]=b[d];puts(b);}/*c%s%c%=a*,'c%'=q
rahc/**//*"=a*,'"'=q rahc/**/
|
| OUTPUT: Same as the
actual source code. This is not only self-reproducible, it's a palindrome
too.
/**/char q='"',*a="*//**/char q='%c',*a=%c%s%c*/};)b(stup;]d[b=]d-852[b)--d(elihw;)q,a,q,q,2+a,b(ftnirps{)(niam;031=d tni;]952[b,",b[259];int d=130;main(){sprintf(b,a+2,q,q,a,q);while(d--)b[258-d]=b[d];puts(b);}/*c%s%c%=a*,'c%'=q rahc/**//*"=a*,'"'=q rahc/**/
|
|
|
| [Q010] Self-reproducible C code
: |
|
t(setq /*;*/){}main(){char q='\"',s='\\';char*a="~%t(setq /*;*/){}main(){char q='~A';char*a=~S;char*b=/*)(setq a ~S)(setq */ ~S;printf(b,s,q,s,s,q,a,q,q,s,s,s,q,s,s,s,s,q,q,b,q/*)(format t /* a /* a */);}~%";char*b=/*)(setq a "\\\"',s='\\\\")(setq */ "t(setq /*;*/){}main(){char q='%c%c',s='%c%c';char*a=%c%s%c;char*b=/*)(setq a %c%c%c%c%c',s='%c%c%c%c%c)(setq */ %c%s%c;printf(b,s,q,s,s,q,a,q,q,s,s,s,q,s,s,s,s,q,q,b,q/*)(format t /* a /* a */);}";printf(b,s,q,s,s,q,a,q,q,s,s,s,q,s,s,s,s,q,q,b,q/*)(format t /* a /* a */);}
|
| OUTPUT: Same as the
actual source code.
t(setq /*;*/){}main(){char q='\"',s='\\';char*a="~%t(setq /*;*/){}main(){char q='~A';char*a=~S;char*b=/*)(setq a ~S)(setq */ ~S;printf(b,s,q,s,s,q,a,q,q,s,s,s,q,s,s,s,s,q,q,b,q/*)(format t /* a /* a */);}~%";char*b=/*)(setq a "\\\"',s='\\\\")(setq */ "t(setq /*;*/){}main(){char q='%c%c',s='%c%c';char*a=%c%s%c;char*b=/*)(setq a %c%c%c%c%c',s='%c%c%c%c%c)(setq */ %c%s%c;printf(b,s,q,s,s,q,a,q,q,s,s,s,q,s,s,s,s,q,q,b,q/*)(format t /* a /* a */);}";printf(b,s,q,s,s,q,a,q,q,s,s,s,q,s,s,s,s,q,q,b,q/*)(format t /* a /* a */);}
|
|
|
|
Send
your feedback about Crazy Coding - Self-reproducible
programs section to nandakishorkn@rediffmail.com
|
|
|
You are
Visitor No. 
Sign
my Guestbook
View
my Guestbook
Make money from your website
Thanks for using C For Swimmers.
Regarding this material, you can send Bug Reports,
Suggestions, Comments, etc. to
nandakishorkn@rediffmail.com

|