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" #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) { void playHangman(char *wordToGuess) {
int mistakes = 0; int mistakes = 0;
@ -19,11 +28,14 @@ void playHangman(char *wordToGuess) {
scanf(" %c", &guess); scanf(" %c", &guess);
// Check if the guess is lower case and is a letter (valid) // 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; continue;
} }
// Convert uppercase letter to lowercase
guess = toLower(guess);
// Check if the guess is a single letter // Check if the guess is a single letter
if (strlen(&guess) != 1) { if (strlen(&guess) != 1) {
printf("Please enter only one letter.\n"); printf("Please enter only one letter.\n");

Loading…
Cancel
Save