home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #19 / NN_1992_19.iso / spool / alt / hackers / 1362 < prev    next >
Encoding:
Text File  |  1992-09-03  |  1.2 KB  |  47 lines

  1. Newsgroups: alt.hackers
  2. Path: sparky!uunet!caen!positron
  3. From: positron@engin.umich.edu (Jonathan Scott Haas)
  4. Subject: Self Printing Program, revisited
  5. Message-ID: <9lm-wK-@engin.umich.edu>
  6. Date: Thu, 03 Sep 92 23:54:41 EDT
  7. Organization: University of Michigan Engineering, Ann Arbor
  8. Approved: Yep.
  9. Nntp-Posting-Host: myrrh.engin.umich.edu
  10. Lines: 35
  11.  
  12. Awhile back, there was talk about how to write a program whose
  13. output would be the program itself. Here's my program, written
  14. in C, but I think perhaps it "cheats" a bit.
  15.  
  16. --clip here---------------------------------------------
  17.  
  18. /*
  19.  * This is a program that should print itself. However, some
  20.  * people might view its algorithm as cheating.
  21.  *
  22.  * Jonathan S. Haas, 3 Sep 92  11:49 pm
  23.  *
  24.  */
  25.  
  26. #include <stdio.h>
  27.  
  28. int main(void)
  29. {
  30.   char in[100];
  31.   FILE *readme;
  32.  
  33.   readme=fopen(__FILE__,"r");
  34.   while(!feof(readme)) {
  35.     fgets(in,99,readme);
  36.     printf("%s",in);
  37.   }
  38.   fclose(readme);
  39. }
  40.  
  41.  
  42. -- 
  43. __/\__  Jonathan S. Haas         | Jake liked his women the way he liked
  44. \    /  University of Michigan   | his kiwi fruit: sweet yet tart, firm-
  45. /_  _\  positron@engin.umich.edu | fleshed yet yielding to the touch, and
  46.   \/                             | covered with short brown fuzzy hair.
  47.