Input will be only lowercase #1

This commit is contained in:
2017-05-01 19:58:44 +02:00
parent 6dfcfcd4ac
commit bedd8b4127
3 changed files with 12 additions and 1 deletions

View File

@@ -2,6 +2,7 @@
#include "hangman.h"
#include <stdlib.h> //atexit
#include <string.h>
#include <ctype.h>
int main(void) {
/* Initialization */
@@ -50,6 +51,7 @@ void initGuessWord(game_state *gs) {
int i;
mvprintw(1, 1, "Please enter your word: ");
getstr(gs->guessWord);
toLowerCase(gs->guessWord);
gs->wordLength = strlen(gs->guessWord);
for (i = 0; i < gs->wordLength; i++) {
if (gs->guessWord[i] == ' ') { //Check for spaces if it's a sentence
@@ -61,6 +63,14 @@ void initGuessWord(game_state *gs) {
clear(); //clear the screen
}
void toLowerCase(char *str) {
int length = strlen(str);
int i;
for (i = 0; i < length; i++) {
str[i] = tolower(str[i]);
}
}
void drawGuessWord(game_state *gs) {
int startpos = gs->centerx - gs->wordLength;
int i, wordpos = 0;

View File

@@ -33,3 +33,4 @@ int fillCurrentWord(game_state *gs, char validchar);
int stackWrongCharacter(game_state *gs, char wrongchar);
int checkWin(game_state *gs);
void printGameStats(game_state *gs);
void toLowerCase(char *str);

View File

@@ -9,7 +9,7 @@ LDFLAGS = -lncurses
OBJ = hangman.o
lcdclock: $(OBJ)
all: $(OBJ)
$(CC) $(CFLAGS) -o hangman $(OBJ) $(LDFLAGS)
%.o: %.c