home *** CD-ROM | disk | FTP | other *** search
/ Source Code 1992 March / Source_Code_CD-ROM_Walnut_Creek_March_1992.iso / usenet / altsrcs / 2 / 2176 / marvin.c < prev    next >
Encoding:
C/C++ Source or Header  |  1990-12-28  |  1.2 KB  |  52 lines

  1. /*
  2.  * MARVIN - Receive a complaint from marvin.
  3.  *
  4.  * If you move the data files for marvin, you need to recompile the
  5.  * program, or nothing will work. To do this, you should be able
  6.  * to simply edit the line "#define MARVIN_PATH..." in marvin.h and then 
  7.  * type "make"
  8.  */
  9.  
  10. #include "marvin.h"
  11.  
  12. /* You shouldn't need to change anything below here. */
  13.  
  14. #include <stdio.h>
  15.  
  16. main()
  17. {
  18.  FILE *f;
  19.  char snum[20], name[1024], str[256];
  20.  int msg, num;
  21.  long now;
  22.  
  23.     /* get the number of available messages */
  24.     if (f = fopen(MARVIN_PATH "number", "rt"))
  25.       {
  26.        fgets(snum, 20, f);
  27.        fclose(f);
  28.       }
  29.     else
  30.       {
  31.        fprintf(stderr, "marvin: number: Could not open.\n");
  32.        exit(1);
  33.       }
  34.     num = atoi(snum);
  35.  
  36.     time(&now);  /* get time value to seed random generator with */
  37.     srand((unsigned) (now % 32767));   /* seed random number generator */
  38.     msg = (int) (rand() % num) + 1; /* get a random message number */
  39.     /* piece together message file name */
  40.     sprintf(snum, "%d", msg);
  41.     strcpy(name, MARVIN_PATH);
  42.     strcat(name, snum);
  43.  
  44.     /* open the message file and print out marvin's complaint */
  45.     if (f = fopen(name, "rt"))
  46.       {
  47.        while (fgets(str, 255, f))
  48.           printf(str);
  49.        fclose(f);
  50.       }
  51. }
  52.