Browse Source

problem with multiple letters

remotes/origin/Saba
Saba Fazlali 11 months ago
parent
commit
db912f56fc
  1. 6
      src/main/c/Hangman/playHangman.c

6
src/main/c/Hangman/playHangman.c

@ -9,6 +9,11 @@ char toLower(char ch) {
return ch;
}
// Ignores all inputs after the first character
void ignoreExtraInput() {
int c;
while ((c = getchar()) != '\n' && c != EOF);
}
void playHangman(char *wordToGuess) {
int mistakes = 0;
@ -26,6 +31,7 @@ void playHangman(char *wordToGuess) {
char guess;
printf("Enter your guess: \n");
scanf(" %c", &guess);
ignoreExtraInput();
// Check if the guess is lower case and is a letter (valid)
if (!isalpha(guess)) {

Loading…
Cancel
Save