Sunday, May 27, 2012

Scramble word finder- C program

/* C program for SCRAMBLE word finding
Download a wordlist.txt file on internet which consists of
all possible english words and save it in your program folder
before running the program. */


#include stdio.h #include string.h void main() { FILE *fp; char scramble[12],word[18],dummy[18],c; int i=0,j=0,wordLen,wordLenS,count=0; clrscr(); fp=fopen("wordlist.txt","r"); printf("enter scrambled word--"); scanf("%s",scramble); wordLenS=strlen(scramble);
while((fgets(word,14,fp))!=0) { strcpy(dummy,word); wordLen=strlen(word); count=0; for(i=0; i { for(j=0; j<(wordLen-1); j++) { if(scramble[i]==word[j]) { count++; word[j]='\0'; break; } } } if((count==wordLenS) && (count==wordLen-1)) { printf("\n\nword Found --%s", dummy); for(j=0;j<16;j++){word[j]='\0';dummy[j]='\0';} } } fclose(fp); getch(); }

No comments:

Post a Comment