🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: comp.std.c
Article #5822

Re: Portable Self-Replicating C Contest

#5822
From: Geoff Clemm
Date: Sat, 25 Mar 1989 18:05
42 lines
1649 bytes
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 <stdio.h>\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 <stdio.h>
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
Technical Details
Message-ID: <GEOFF.89Mar25130500@tom.harvard.edu>
Path: arc1-ca.pugleaf.net!utzoo!utgpu!jarvis.csri.toronto.edu!mailrus!tut.cis.ohio-state.edu!bloom-beacon!husc6!geoff
References: <2179@fireball.cs.vu.nl> <2976@goofy.megatest.UUCP> <12144@haddock.ima.isc.com>

Show Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!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: <GEOFF.89Mar25130500@tom.harvard.edu>
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