Search code examples
c#wordsearch

Scrabble word finder in C#


What I'm trying to do right now is take a user input, and check a text file to see if you can make any of the words in the text file out of the input entered.

For example, if I entered "noqmopu", the output would be: moo moon mop muon pun quo upon

My code is below. I've omitted the rest of the program since it's finished and would use up space. What I've tried to do is, if the inputted string is larger than the word that is being checked in the text file, it'll convert both to a char then compare each letter of the input to the word. If the characters match, a counter adds 1 to itself and the for loop breaks to prevent a letter being matched twice. Then, if the counter is equal to the length of the word, that would mean you could make out the word from the inputted string and it gets printed on the screen.

At the moment, if I type "noqmopu", all that gets printed out is 'n' (which is one of the words in the text file). I realize I'll have to limit the printed words to words with 3 characters or higher, but I'd like to know how to resolve this first. If there's another way of doing this, that'd be great, but I'd also like to know why this isn't working. I can't use any Systems.Collections. Thanks.


Solution

  • You're looping over the line twice:

    for (int i = 0; i < line.Length; i++)
    {
        for (int j = 0; j < line.Length; j++)
        {
    

    I think one of those was supposed to be looping over the input