Is there any way that I can search for "tro_ _ _e" where the underscores represent missing letters?
I have a text file with a 7 letter word on each line. e.g
trouble
control
reached
further
helping
shatter
biggest
I am trying to compare each word to the string
char check[10]="tro\0\0\0e"
at the moment I am reading each line and comparing using:
if(strstr(pword,check)!=NULL)
{
fprintf(wfile,"%s\n",pword);
}
}
fclose(file);
fclose(wfile);
I realise that my current output in wfile:
control
trouble
is due to the fact that there are three \0s in between the "tro" and the "e" and so the comparison is just finding "tro" in the words.
Is there any way that I can search for "tro_ _ _e" where the underscores represent missing letters?
This is for a hangman game and so the words in the file are not always the same, not always 7 letters long and the pattern is not always "tro_ _ _e" as the pattern represents the letters already guessed by a player. The answer in this case: "trouble"
For example, if a player guessed "r", "u" and "l". I would have a string which was literally.
char check[10]="\0r\0u\0l\0\0\0\0\0"
so the search I would want would be for any words with a pattern "_r_u_l"
If you are truly open to a C# solution, as suggested by your tags: