I\'m getting an error with my to_lower function see here: //preprocessor directi
ID: 3621734 • Letter: I
Question
I'm getting an error with my to_lower function see here:
//preprocessor directives
#define _CRT_SECURE_NO_DEPRECATE
#include
#include
#include
#define SIZE 20
#define MAX_GUESSES 6
//Function Prototypes
//Print Greeting
void printGrtg ( );
//Gets choice of to play or not
char GetChoice(void);
//Scans in letter
char guessLet (void);
//Resets Variables
void resetVar(void);
//Prints Starword based off length
void printStar (char word[SIZE],char starword[SIZE]);
//Prototype for finding if letter is in word
int compare ( char word[], char letter);
//Based on comparsion, checks whether it should update star word or not
void IndexResult(int found, char letter,char *starword,int *numberRight, int *numberWrong);
int main()
{
//Declaring variables
char guess= ' ';
char choice =' ';
char word[SIZE];
char starword[SIZE];
char letter= ' ';
int found;
int numberRight;
int numberWrong;
int gameOver;
FILE *inptr;
//prints the greeting
printGrtg ( );
//opens file words.txt
inptr = fopen("words.txt", "r");
//resets variables
do{
numberRight=0;
numberWrong=0;
gameOver=0;
//scans in word
fscanf(inptr, "%s",word);
//Makes a starword based off word received
printStar(word,starword);
//main loop for the game
do {
//function call-gets letter
letter =guessLet();
//function call-compares if the letter was found in the array
found = compare (word,letter);
//function call-if the letter was found or not, updates accordingly
IndexResult(found, letter,starword,&numberRight, &numberWrong);
//If statements for if user has won or not
if(numberRight==strlen(word))
{
printf("Congrats! ");
gameOver = 1;
}
if (numberWrong >= MAX_GUESSES)
{
printf("You lose ");
printf("****You did not win- the word was %s****",word);
gameOver = 1;
}
}while (!gameOver);
//gets menu choice
choice = GetChoice();
//If selection does not equal choice, will play again
}while(choice!='q'&& choice!='Q');
//prints goodbye if user does not want to play anymore
printf (" GOODBYE ");
return 0;
}
//Function definition for printing the instructions
void printGrtg ( )
{
printf("WELCOME TO HANGMAN! ");
printf("Please read the following instructions before you play. ");
printf("You will be presented with a word to be guessed. ");
printf("Guess letters one at a time. ");
printf("You can have up to SIX incorrect guesses. ");
printf("The game will be OVER when you have guessed ");
printf("all the letters in the word ");
printf("or when you have guessed incorrectly SIX times. ");
printf(" HAVE FUN! ");
printf("-------------------- ");
printf("-------------------- ");
}
//Function definition on whether or not user wants to play again
char GetChoice(void)
{
char selection;
printf(" Enter (Q ) to QUIT, anything else to continue: ");
scanf(" %c", &selection);
return selection;
}
//Function definition for reseting variables
void reset(void)
{
int numberRight=0;
int numberWrong=0;
int gameOver=0;
}
//Function definition for printing star word based on length
void printStar (char word[SIZE],char starword[SIZE])
{
int i;
int length;
length=strlen(word);
for(i=0;i
{
starword[i] = '*';
}
starword[length]= '';
printf("Guess this word: ");
printf(" %s ",starword);
}
//Function definition for getting letter guessed
char guessLet (void)
{
char buff[128];
printf("Enter a letter: ");
scanf(" %s",buff);
return to_lower (buff[0]);
}
//Function definition for finding if letter is in word
int compare ( char word[], char letter)
{
int i;
for(i=0;i
{
if(word[i] == letter)
{
return i;
}
}
return -1;
}
//Function definition - checks whether it should update star word or not
void IndexResult(int found, char letter,char *starword,int *numberRight, int *numberWrong)
{
if(found == -1)
{
printf(" Your letter is NOT in the word!");
(*numberWrong)++;
printf(" Number of wrong guesses %d ,MAX 6",*numberWrong);
}
else
{
if(starword[found]== '*')
{
printf(" Your letter is in the word!");
(*numberRight)++;
starword[found]= letter;
}
else
{
printf("duplicate letter");
}
}
printf(" %s ",starword);
}
Explanation / Answer
You have your function call for to_lower, it's tolower
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.