Xref: utzoo comp.misc:5572 comp.lang.c:17065 Path: utzoo!attcan!uunet!mcvax!hp4nl!botter!star.cs.vu.nl!maart From: maart@cs.vu.nl (Maarten Litmaath) Newsgroups: comp.misc,comp.lang.c Subject: Re: Silly programming problems Message-ID: <2179@fireball.cs.vu.nl> Date: 17 Mar 89 16:57:38 GMT References: <817@krafla.rhi.hi.is> Organization: V.U. Informatica, Amsterdam, the Netherlands Lines: 31 frisk@rhi.hi.is (Fridrik Skulason) writes: \ "write a one line C program that produces the source code \ to itself when run." Spoilers: Actually a 2 liner (doesn't exceed 80 character limit): ----------8<----------8<----------8<----------8<----------8<---------- char*p="char*p=%c%s%c%c;main(){printf(p,34,p,34,10,10);}%c" ;main(){printf(p,34,p,34,10,10);} ----------8<----------8<----------8<----------8<----------8<---------- A true 1 liner (join the 2 lines): ----------8<----------8<----------8<----------8<----------8<---------- char*p="char*p=%c%s%c;main(){printf(p,34,p,34,10);}%c";main(){printf(p,34,p,34, 10);} ----------8<----------8<----------8<----------8<----------8<---------- The program below won't print a terminating newline, so the source shouldn't contain '\n'. (Is this OK with ANSI?) ----------8<----------8<----------8<----------8<----------8<---------- char*p="char*p=%c%s%c;main(){printf(p,34,p,34);}";main(){printf(p,34,p,34);} ----------8<----------8<----------8<----------8<----------8<---------- A cheat. ----------8<----------8<----------8<----------8<----------8<---------- main(){execlp("cat","",__FILE__,(char*)0);} ----------8<----------8<----------8<----------8<----------8<---------- -- Those against Rushdie haven't |Maarten Litmaath @ VU Amsterdam: learned anything from the Dark Ages. |maart@cs.vu.nl, mcvax!botter!maart