Path: utzoo!attcan!uunet!lll-winken!scooter!neoucom!sam From: sam@neoucom.UUCP (Scott A. Mason) Newsgroups: comp.misc Subject: Re: Silly programming problems Message-ID: <1544@neoucom.UUCP> Date: 22 Mar 89 18:58:36 GMT References: <817@krafla.rhi.hi.is> Reply-To: sam@neoucom.UUCP (Scott A. Mason) Organization: Northeastern Ohio Universities College of Medicine Lines: 29 In article <817@krafla.rhi.hi.is> frisk@rhi.hi.is (Fridrik Skulason) writes: > > "write a one line C program that produces the source code > to itself when run." > I'm assuming that the intent of a "one line" program is that it is one line of code, not including the header and variable declarations. The only other assumption made is that the source has a ".c" extension to the program being run. Otherwise, here's my program. ---------------------------------- #include main (argc, argv) int argc; char *argv[]; { FILE *fp; int ch; for ((strcat (argv[0], ".c")) && (fp = fopen (argv[0], "r")); (ch = getc (fp)) != EOF; putchar (ch) ) ; } ---------------------------------- Notice, that the code part is only one statement long. It certainly could have been written as one text line, but it would have been slightly less readable by many terminals. -------------------------------------------------------------------------------- "If it ain't broke, don't fix it," and certainly don't blame me. UUCP: {pitt, scooter, hal, cwjcc}!neoucom!sam INTERNET: sam@neoucom.UUCP Scott A. Mason Coordinator of Systems Operations, NEOUCOM