Path: utzoo!utgpu!jarvis.csri.toronto.edu!mailrus!tut.cis.ohio-state.edu!bloom-beacon!husc6!geoff From: geoff@tom.harvard.edu (Geoff Clemm) Newsgroups: comp.std.c Subject: Re: Portable Self-Replicating C Contest Message-ID: Date: 25 Mar 89 18:05:00 GMT References: <2179@fireball.cs.vu.nl> <2976@goofy.megatest.UUCP> <12144@haddock.ima.isc.com> Sender: news@husc6.harvard.edu Followup-To: comp.std.c Distribution: usa Organization: Aiken Computation Lab, Harvard University Lines: 42 In-reply-to: karl@haddock.ima.isc.com's message of 23 Mar 89 17:45:03 GMT Here is an old self-replicating program I did a while back ... no attempt was made to make the program short. It may not be ansi but it should be trivial to make it so. ------------ cut here ----------------- char *text = "\n\ #include \n\ main()\n\ {\n\ (void)printf(\"char *text =\\n\\\"\");\n\ out(text);\n\ (void)printf(\"\\\";\\n%s\\n\", text); exit(0);};\n\ \n\ out(s)\n\ char *s;\n\ {\n\ while (*s != 0) {\n\ if (*s == '\\n') (void)printf(\"\\\\n\\\\\");\n\ if (*s == '\\\\' || *s == '\"') (void)putchar('\\\\');\n\ (void)putchar(*s); s += 1; };};\n\ "; #include main() { (void)printf("char *text =\n\""); out(text); (void)printf("\";\n%s\n", text); exit(0);}; out(s) char *s; { while (*s != 0) { if (*s == '\n') (void)printf("\\n\\"); if (*s == '\\' || *s == '"') (void)putchar('\\'); (void)putchar(*s); s += 1; };}; ------------ cut here ----------------- Geoff Clemm geoff@harvard.harvard.edu