self reproducing program

teklabs!tekcrd!azure!randals teklabs!tekcrd!azure!randals
Thu Nov 4 10:34:39 AEST 1982

My favorite short self-reproducing (but not too portable) program is this:

main(){char q=34,n=10,*a="main(){char q=34,n=10,*a=%c%s%c;printf(a,q,a,q,n);}%c";printf(a,q,a,q,n);}

This is all one line.  There *must* be a newline at the end, or the C compiler
(usually) barfs.

I can't take credit for this one, but I don't remember where I got it.

Randal L. Schwartz
Tektronix Microcomputer Development Products
Beaverton, Oregon, USA

UUCP:	...!{ucbvax or decvax}!teklabs!tekmdp!randals (ignore return address)
CSNET:	tekmdp!randals @ tektronix
ARPA:	tekmdp!randals.tektronix @ rand-relay

More information about the Comp.lang.c mailing list