void FindWord (char used , char string , int wordsize);
char* CleanString (char string, int wordsize);
int main (void)
input_size = wordsize = 0;
fp = fopen("dictionary.txt","r");/*contains a list of words in the following format : number_of_chars.word (i.e. 2.hi , 4.stop )*/
printf("Type the letters and press enter : ");
gets(letters);/* saves the inputed data to a string*/
input_size = strlen(letters);/* gets how many characters user entered*/
fscanf(fp,"%d",&wordsize);/* will read the number (i.e. for 2.hi will read 2) to determine the size of the word*/
string = fgets(words, 30 , fp);
strcpy(used, letters);/*copies the inputed string into a new array , go to FindWord () for details*/
if (string == NULL) /*if the file ends or we have an error, break*/
if (input_size != wordsize) /*if the number of letters we inputed is different from the size of the word in question , skip it*/
CleanString (string, wordsize);/*This function removes the number_of_letters. from the string "string" .*/
FindWord (used, string, wordsize);/* this function checks if the letters inputed can make a word and if so , prints it*/
void FindWord (char used , char string , int wordsize)
int match = 0;
for ( int i = 0; i<=wordsize; i++)
for ( int j = 0; j<=wordsize; j++)
if (used[j] == string[i])/*the used array is just a copy of the inputed string*/
match++;/*inputed character matches the one of the word*/
used[j] = 0;/*replaces the matched character with 0 so we don't end up using it again (better way to do this?)*/
if (match == wordsize )/*if we matched as many characters as the characters in the word then print it */
char* CleanString (char string, int wordsize)
for (int i = 0; i<wordsize; i++)
if (string[i] == '.')
for (int j = 0; j <= wordsize; j++)
string[j] = string[(i+1)+j];
1) How can i make it work with greek words? (my windows are in english)
if i use a dictionary with greek words it shows them as blank space. 2) Why my first while works only once? 3) Why if i enter a printf under strcpy(used, letters); it takes ALOT longer to compute?
The program will ask the user to enter some letters and will try to find if that letters can make a word.
To do that it reads data from a file called dictionary.
example of dictionary.txt :
3.yes As you can see we have the number of letters a word contains followed by a '.' and the word.
This is needed so that we only compare words with as many letters as the user typed.
For example , if user enters "opst" the output will be something like this :
It works with English (gets the job done) , but i want to know how can i do this with languages like Greek.