Browse Source

handle upper case letters

remotes/origin/Saba
Saba Fazlali 11 months ago
parent
commit
924e747d2a
  1. 16
      src/main/c/Hangman/playHangman.c

16
src/main/c/Hangman/playHangman.c

@ -1,5 +1,14 @@
#include "playHangman.h"
// Converts the letter to lower case
char toLower(char ch) {
// Convert uppercase letter to lowercase manually
if (ch >= 'A' && ch <= 'Z') {
return ch + ('a' - 'A');
}
return ch;
}
void playHangman(char *wordToGuess) {
int mistakes = 0;
@ -19,11 +28,14 @@ void playHangman(char *wordToGuess) {
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");
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 single letter
if (strlen(&guess) != 1) {
printf("Please enter only one letter.\n");

Loading…
Cancel
Save