Hi all, I wrote this function for a hangman game I am making. This function is supposed to take in prompt for a letter as a guess then check it against two arrays, one wrongly guessed letters and one with right guesses. What happens is that it asks for a guess then you enter a letter and it just stops. You can keep hard returning, but it doesnt do anything past that.
Thanks for the help in advance,
Evan
Code:
int getGuess(char display[], char wrong[], int misses)
{
char guess;
int valid;
printf("Enter a character to guess:");
guess=scanf("%c",&guess);
valid=1;
while(valid==1)
{
if(guess>='a' && guess<='z')
{
while (*wrong != '\0' && *wrong != guess )
{ wrong++;
if( *wrong == '\0' )
valid=1;
else
valid=0;
}
while (*display != '\0' && *display != guess )
{ display++;
if( *display == '\0' )
valid=1;
else
valid=0;
}
}
if(valid==0)
{
printf("Try again!");
}
}
return guess;
}