home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Game Killer
/
Game_Killer.bin
/
641.JUMBLE.C
< prev
next >
Wrap
Text File
|
1992-12-19
|
2KB
|
95 lines
/*
Copyright (c) 1992 Charles Bower
Permission is granted to modify or redistribute this code provided
this message is left intact.
The code is kind of ugly, and undocumented. Don't complain, you got
it for free.
Note: the name of the dictionary is defined in jumble.h
*/
#include <string.h>
#include <stdio.h>
#include <ctype.h>
#include "jumble.h"
main()
{
int notfound=1;
FILE *dfile;
void l_count();
char word[MAXLENGTH];
int let_cnt[26];
int let_cnt_d[26];
char dword[MAXLENGTH];
register int wordlen;
if ((dfile=fopen(DICTIONARY,"r"))==NULL)
{
printf("Error opening dictionary");
exit(1);
}
printf("Please enter a word to be descrambled ->");
gets(word);
while (!is_vld(word))
{
printf("The word must be all letters!!\nPlease try again ->");
gets(word);
}
wordlen=strlen(word);
l_count(word,let_cnt);
while (fscanf(dfile,"%s",dword)!=EOF)
if ((wordlen == strlen(dword)) && is_vld(dword))
{
l_count(dword,let_cnt_d);
if (!c_count(let_cnt,let_cnt_d))
{
notfound=0;
printf("%s\n",dword);
}
}
if (notfound)
printf("Sorry, no word could be found.\n");
close(dfile);
return(0);
}
is_vld(word)
char *word;
{
register int cnt;
register int valid=1;
valid=strlen(word);
for (cnt=0;(valid&&(cnt<strlen(word)));cnt++)
valid=isalpha(word[cnt]);
return(valid);
}
void l_count(wrd,cnt)
int *cnt;
char *wrd;
{
register int index;
for (index=0;index<26;index++)
*(cnt+index)=0;
for (index=0;index<strlen(wrd);index++)
cnt[tolower(wrd[index])-'a']++;
}
c_count(a1,a2)
int *a1,*a2;
{
register int index, notequal=0;
for (index=0;((index<26)&&(!notequal));index++)
notequal+= !(*(a1+index)==*(a2+index));
return(notequal);
}