home *** CD-ROM | disk | FTP | other *** search
- #include <iostream.h>
- #include <fstream.h>
- #include <stdio.h>
- #include <stdlib.h>
- #include <ctype.h>
- #include <string.h>
- #include "array.h"
-
- int count,num,found=0;
- Array<char *> results;
-
- void look_for_em(char *image)
- { ifstream f;
- int i;
- char ques[10],buf[25];
- f.open("/usr/dict/words", ios::in);
- if (!f)
- {cerr << "Can not open the Dictionary file /usr/dict/words" << endl;
- exit(4);}
- while ( f >> buf)
- { if (num != strlen(buf)) continue;
- for(i=0;i<num;i++)
- { if (image[i] == '_') continue;
- if (i==0 && (buf[i]>image[i]) )
- { i=-2;
- break;}
- if (image[i]!=buf[i])
- { i=-3;
- break;}
- }
- if (i==-2) break;
- if (i==-3) continue;
- results[found++] = strcpy(new char[num+1],buf);
- if (found == count)
- { break;
- }
- }
- }
-
- main (int argc, char* argv[])
- { if (argc != 4)
- { cout << endl <<
- "Use: swords <number of char in word> <word with _ as unknown char> <max to return>"
- << endl << endl;
- return 1;
- }
- num=atoi(argv[1]);
- count=atoi(argv[3]);
- look_for_em(argv[2]);
- cout << results << endl;
- return 0;}
-