home *** CD-ROM | disk | FTP | other *** search
/ Usenet 1994 October / usenetsourcesnewsgroupsinfomagicoctober1994disk2.iso / games / volume4 / bog / mkdict.c < prev    next >
C/C++ Source or Header  |  1988-03-09  |  1KB  |  66 lines

  1. /* vi: set tabstop=4 : */
  2.  
  3. /*
  4.  * Filter out words that:
  5.  *    1) Are not completely made up of lower case letters
  6.  *    2) Contain a 'q' not immediately followed by a 'u'
  7.  *    3) Are less that 3 characters long
  8.  *    4) Are greater than MAXWORDLEN characters long
  9.  */
  10.  
  11. #include <ctype.h>
  12. #include <stdio.h>
  13.  
  14. #include "bog.h"
  15.  
  16. main(argc, argv)
  17. int argc;
  18. char **argv;
  19. {
  20.     register char *p, *q, *r;
  21.     register int ch, common, i, n;
  22.     int current, len, prev, qcount;
  23.     char buf[2][MAXWORDLEN + 1];
  24.  
  25.     prev = 0;
  26.     current = 1;
  27.     buf[prev][0] = '\0';
  28.     if (argc == 2)
  29.         n = atoi(argv[1]);
  30.     i = 1;
  31.     while (gets(buf[current]) != (char *) NULL) {
  32.         if (argc == 2 && i++ % n)
  33.             continue;
  34.         len = 0;
  35.         for (p = buf[current]; *p != '\0'; p++) {
  36.             if (!islower(*p))
  37.                 break;
  38.             if (*p == 'q') {
  39.                 q = p + 1;
  40.                 if (*q != 'u')
  41.                     break;
  42.                 else {
  43.                     while (*q = *(q + 1))
  44.                         q++;
  45.                 }
  46.                 len++;
  47.             }
  48.             len++;
  49.         }
  50.         if (*p != '\0' || len < 3 || len > MAXWORDLEN)
  51.             continue;
  52.  
  53.         p = buf[current];
  54.         q = buf[prev];
  55.         qcount = 0;
  56.         while ((ch = *p++) == *q++ && ch != '\0')
  57.             if (ch == 'q')
  58.                 qcount++;
  59.         common = p - buf[current] - 1;
  60.         printf("%c%s", common + qcount, p - 1);
  61.         prev = !prev;
  62.         current = !current;
  63.     }
  64. }
  65.  
  66.