|
|
@ -14,9 +14,21 @@ void playHangman(char *wordToGuess) { |
|
|
|
|
|
|
|
// Get a letter from the player |
|
|
|
char guess; |
|
|
|
printf("\n\t Enter your guess (lower case): "); |
|
|
|
printf("Enter your guess: \n"); |
|
|
|
scanf(" %c", &guess); |
|
|
|
|
|
|
|
// check if the guess is lower case and is a letter (valid) |
|
|
|
if (!isalpha(guess) || isupper(guess)) { |
|
|
|
printf("Please enter a valid lowercase alphabet.\n"); |
|
|
|
continue; |
|
|
|
} |
|
|
|
|
|
|
|
// 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; |
|
|
|
|
|
|
|