#include
#include
#include
#include
#include
#include
#include
#include
#include
#include "array.h"
int count,num,found=0;
Array 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;iimage[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)
{ results[found++] = strcpy(new char [3],",,,");
break;
}
}
if (found < count) results[found++] = strcpy(new char [3],",,,");
cout << "I found " << found-1 << " word(s)." << endl;
}
main (int argc, char* argv[])
{ if (argc != 4)
{ cout << endl << "Correct Use: swords " << endl << endl;
return 1;
}
num=atoi(argv[1]);
count=atoi(argv[3]);
look_for_em(argv[2]);
cout << results << endl;
struct tms t1;
times(&t1);
cout << "CPU time: " << (float(t1.tms_utime)/float(sysconf(3))) << " sec." << endl;
return 0;}
http://blackcat.brynmawr.edu/~nswoboda/scripts/swords.C
(possibly inaccurate URL)
07/1998