home *** CD-ROM | disk | FTP | other *** search
/ Game Killer / Game_Killer.bin / 641.JUMBLE.C < prev    next >
Text File  |  1992-12-19  |  2KB  |  95 lines

  1. /*
  2. Copyright (c) 1992 Charles Bower
  3.  
  4. Permission is granted to modify or redistribute this code provided
  5. this message is left intact. 
  6.  
  7. The code is kind of ugly, and undocumented.  Don't complain, you got
  8. it for free.  
  9.  
  10. Note: the name of the dictionary is defined in jumble.h
  11. */
  12.  
  13. #include <string.h>
  14. #include <stdio.h>
  15. #include <ctype.h>
  16. #include "jumble.h"
  17.  
  18. main()
  19. {
  20. int notfound=1;
  21. FILE *dfile;
  22. void l_count();
  23. char word[MAXLENGTH];
  24. int let_cnt[26];
  25. int let_cnt_d[26];
  26. char dword[MAXLENGTH];
  27. register int wordlen;
  28.  
  29. if ((dfile=fopen(DICTIONARY,"r"))==NULL)
  30.   {
  31.   printf("Error opening dictionary");
  32.   exit(1);
  33.   }
  34. printf("Please enter a word to be descrambled ->");
  35. gets(word);
  36. while (!is_vld(word)) 
  37.   {
  38.   printf("The word must be all letters!!\nPlease try again ->");
  39.   gets(word);
  40.   }
  41. wordlen=strlen(word);
  42. l_count(word,let_cnt);
  43. while (fscanf(dfile,"%s",dword)!=EOF)
  44.   if ((wordlen == strlen(dword)) && is_vld(dword)) 
  45.     {
  46.     l_count(dword,let_cnt_d);
  47.     if (!c_count(let_cnt,let_cnt_d))
  48.       {
  49.       notfound=0;
  50.       printf("%s\n",dword);
  51.       }
  52.     }
  53. if (notfound)
  54.   printf("Sorry, no word could be found.\n");
  55. close(dfile);
  56. return(0);
  57. }
  58.  
  59.  
  60. is_vld(word)
  61. char *word;
  62. {
  63. register int cnt;
  64. register int valid=1;
  65.  
  66. valid=strlen(word);
  67. for (cnt=0;(valid&&(cnt<strlen(word)));cnt++)
  68.   valid=isalpha(word[cnt]);
  69. return(valid);
  70. }
  71.  
  72.  
  73. void l_count(wrd,cnt)
  74. int *cnt;
  75. char *wrd;
  76. {
  77. register int index;
  78.  
  79. for (index=0;index<26;index++)
  80.   *(cnt+index)=0;
  81. for (index=0;index<strlen(wrd);index++)
  82.   cnt[tolower(wrd[index])-'a']++;
  83. }
  84.  
  85.  
  86. c_count(a1,a2)
  87. int *a1,*a2;
  88. {
  89. register int index, notequal=0;
  90.  
  91. for (index=0;((index<26)&&(!notequal));index++)
  92.   notequal+= !(*(a1+index)==*(a2+index));
  93. return(notequal);
  94. }
  95.