Well, there's lots to work on here. First of all
word
and
sol
are initialized to empty arrays, but you populate more members than they contain in lines 11 and 27. For a beginner project like this, why don't you assume a maximum word length like 80 characters or something. You would then change lines 6 and 7 to something like:
1 2
|
char word[80]="";
char sol[80]="";
|
There are more elegant ways to do this, but that will work for now.
You are obviously working on loops. So figure out what needs to be in your loop and what the condition(s) is/are that will break you out of the loop.
Off the top of my head, I think the loop should contain:
- Printout of the guessed letters so far
- Statement of how many guesses (actually, incorrect guesses) remain
- Prompt for a letter
- Refresh screen
- Statement indicating if last guess was correct
You will leave the loop if
- You guessed the entire word
- You run out of guesses
You have a lot of those elements in your code, but there is no outer loop to contain them all.