So I made a hangman game but it won't compile...I'm so lost
Code:
#include <stdio.h>
#include <string.h>
#include <ctype.h>
#define MAXWORD 20 //max word length
#define INCORRECT_GUESSES 9 //max # of guesses allowed
/* Prototypes */
void fill_array( char *theArray, int howMany, char theLetter ); // Fills theArray with howMany copies of theLetter
int get_letter( char *theWord, char *soFar ); // Get char from player, checks the letter, shows progress so far
int letter_in_word( char *theWord, char *soFar, char theLetter ); // Check if letter is in word, updates progress so far
void lower_string( char *someWord ); // Convert the word to lowercase
void play( char *theWord ); // Play one game
/* Function definitions */
int main( )
{
char theWord[ MAXWORD ]; //theWord is an array of characters with the length of MAXWORD
char *someWord; //the word that will be read from the file
FILE *ifp = fopen( "guesswords.txt", "r" ); //open myFile to read
if (ifp == NULL ) //if file doesn't exist
{
printf( "File does not exist\n" );
return -1; //return code
}
fscanf(ifp, "%s", theWord); //scans word from file
lower_string(someWord); //invokes the function lower_string
play(theWord); //passing theWord into play function
fclose(ifp); //closes file
return 0; //all done
}
/* *********************************************************************** */
void fill_array( char *theArray, int howMany, char theLetter ) // Fills theArray with howMany copies of theLetter
{
int i;
for( i = 0; i < howMany; ++i)
{
theArray[i] = theLetter;
}
}
/* *********************************************************************** */
// Get char from player, checks the letter, shows progress so far
int get_letter( char *theWord, char *soFar )
{
char theLetter;
printf("Please enter a letter: \n");
scanf("%c", &theLetter);
theLetter = tolower(theLetter);
letter_in_word(theWord, soFar, theLetter);
}
/* *********************************************************************** */
int letter_in_word( char *theWord, char *soFar, char theLetter ) // Check if letter is in word, updates progress so far
{
int i;
int numberOfMatches;
for( i = 0; i < strlen(theWord); ++i )
{
if (theWord[i] == theLetter)
{
soFar[i] = theLetter;
++numberOfMatches;
}
if (numberOfMatches == 0)
{
printf("Oops! The letter you guessed is not in the word!\n");
return 0; //not found
}
else
{
printf("Yay! The letter you guessed is in the word!\n");
printf("%s", soFar);
return 1; //1 or more was found
}
}
return numberOfMatches;
}
/* *********************************************************************** */
void lower_string ( char *someWord ) // Convert the word to lowercase
{
int i;
for (i = 0; i < strlen(someWord); ++i)
{
someWord[i] = tolower(someWord[i]);
}
}
/* *********************************************************************** */
void play( char *theWord ) // Play one game
{
char theWord[MAXWORD];
int maxGuesses = INCORRECT_GUESSES;
char soFar[MAXWORD];
int result;
int i;
fill_array( soFar, strlen(theWord), '*' );
printf("%s", soFar);
for (int i = 0; i < INCORRECT_GUESSES; ++i)
{
result=get_letter(theWord, soFar);
if ( result = 0 )
{
printf("You have %d more letters to guess! Keep guessing!", i);
}
else if ( result = 1 )
{
printf("You have guessed all letters! Good job!");
}
printf("The word was %c", theWord);
}
}
// End of program