diff --git a/src/main/c/Hangman/playHangman.c b/src/main/c/Hangman/playHangman.c index bc6141e..86865f5 100644 --- a/src/main/c/Hangman/playHangman.c +++ b/src/main/c/Hangman/playHangman.c @@ -55,22 +55,32 @@ void playHangman(char *wordToGuess) { printf("Enter your guess: \n"); scanf("%s", input); - // Check if a valid character is entered - if (guess == '\0') { + // Check if the input is a single letter + if(strlen(input) > 1) { printf("Invalid input. Please enter a single letter.\n"); continue; } + // Check if the input is an alphabet + char guess = input[0]; + if (!isalpha(guess)) { + printf("Please enter a valid alphabet.\n"); + continue; + } + // Convert uppercase letter to lowercase guess = toLower(guess); - // Check if the guess is a letter (valid) - if (!isalpha(guess)) { - printf("Please enter a valid alphabet.\n"); - ignoreExtraInput(); + // Check if the letter has already been guessed by the player + if (strchr(guessedLetters, guess) != NULL) { + printf("You already guessed that letter. Try another letter.\n"); continue; } + // Add the guessed letter to the list + guessedLetters[strlen(guessedLetters)] = guess; + + // Check if the letter has already been guessed by the player if (strchr(guessedLetters, guess) != NULL) { printf("You already guessed that letter. Try another letter.\n");