Browse Source

refactoring + some bugs fixed

remotes/origin/Saba
Saba Fazlali 11 months ago
parent
commit
9cd6f1e3be
  1. 22
      src/main/c/Hangman/playHangman.c

22
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");

Loading…
Cancel
Save