From db912f56fcea6da0a78492afd2fe5860a5afe388 Mon Sep 17 00:00:00 2001 From: Saba Fazlali Date: Fri, 2 Feb 2024 17:49:16 +0100 Subject: [PATCH] problem with multiple letters --- src/main/c/Hangman/playHangman.c | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/main/c/Hangman/playHangman.c b/src/main/c/Hangman/playHangman.c index 19ab800..abd40b6 100644 --- a/src/main/c/Hangman/playHangman.c +++ b/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)) {