home *** CD-ROM | disk | FTP | other *** search
/ Packard Bell - Internet on a CD / internet on a cd.cdr / Internet / sites / HTML_1 / swords-simple.C < prev    next >
Encoding:
C/C++ Source or Header  |  1998-07-16  |  1.1 KB  |  52 lines

  1. #include <iostream.h>
  2. #include <fstream.h>
  3. #include <stdio.h>
  4. #include <stdlib.h>
  5. #include <ctype.h>
  6. #include <string.h>
  7. #include "array.h"
  8.  
  9. int count,num,found=0;
  10. Array<char *> results;
  11.  
  12. void look_for_em(char *image)
  13. { ifstream f; 
  14.   int i;
  15.   char ques[10],buf[25];
  16.   f.open("/usr/dict/words", ios::in);
  17.   if (!f)
  18.         {cerr << "Can not open the Dictionary file /usr/dict/words" << endl;
  19.           exit(4);}
  20.   while ( f >> buf)
  21.      { if (num != strlen(buf)) continue; 
  22.        for(i=0;i<num;i++)
  23.       { if (image[i] == '_') continue; 
  24.          if (i==0 && (buf[i]>image[i]) )
  25.           { i=-2;
  26.             break;}
  27.             if (image[i]!=buf[i])
  28.           { i=-3;
  29.          break;}
  30.              }
  31.        if (i==-2) break;
  32.        if (i==-3) continue;
  33.        results[found++] = strcpy(new char[num+1],buf);
  34.        if (found == count)
  35.       { break;
  36.        }
  37.        }
  38.   }
  39.  
  40. main (int argc, char* argv[])
  41. { if (argc != 4) 
  42.       { cout << endl <<
  43.       "Use: swords <number of char in word> <word with _ as unknown char> <max to return>" 
  44.                << endl << endl;
  45.         return 1;
  46.     }
  47.   num=atoi(argv[1]);
  48.   count=atoi(argv[3]);
  49.   look_for_em(argv[2]);
  50.   cout << results << endl;
  51.   return 0;}
  52.