home *** CD-ROM | disk | FTP | other *** search
/ The C Users' Group Library 1994 August / wc-cdrom-cusersgrouplibrary-1994-08.iso / vol_100 / 182_01 / updatequ.c < prev    next >
Text File  |  1990-07-31  |  1KB  |  59 lines

  1. #include    <stdio.h>
  2.  
  3. FILE    *seekfp,        /* the address file */
  4.     *fortfp;        /* the actual fortune file */
  5.  
  6. #include     <quip.h>
  7.  
  8. openfiles()
  9. {
  10.     seekfp = fopen(seekname, "w");
  11.     if (seekfp == 0) {
  12.         puts("Cannot open address file.");
  13.         exit(0);
  14.     }
  15.     fortfp = fopen(quipname, "r");
  16.     if (fortfp == 0) {
  17.         puts("Cannot open fortunes file.");
  18.         exit(0);
  19.     }
  20. }
  21.  
  22. putaddr(addr)
  23. long    addr;
  24. {
  25.     if (fwrite((char *)&addr, sizeof(long), 1, seekfp) < 1)
  26.         printf("write error on address file\n");
  27. }
  28.  
  29. int figureforts()
  30. {
  31.     int    c,
  32.         count = 0;
  33.     char    line[128];
  34.  
  35.     putaddr(0L);
  36.     for (;;) {
  37.         if (fgets(line, 128, fortfp) == 0)
  38.             return count;
  39.         if (line[0] == '.') {
  40.             putaddr((long)ftell(fortfp));
  41.             count++;
  42.         }
  43.     }
  44. }
  45.  
  46. closefiles()
  47. {
  48.     fclose(seekfp);
  49.     fclose(fortfp);
  50. }
  51.  
  52. main()
  53. {
  54.     openfiles();
  55.     printf("files open\n");
  56.     printf("there are %d quips",figureforts());
  57.     closefiles();
  58. }
  59.