This is my complete program if it helps.
Code:
#include<stdio.h>#include<ctype.h>
#include<string.h>
#define S 25
//function prototypes
//displays instructions for user
void Instructions();
//displays character arrays
void DisplayArray(char array[]);
//prompts user to enter a letter
char GuessLetter();
//compares arrays to see if they match or not
int CompareArray(char arraya[], char arrayb[]);
//function that returns the index of the letter that the user has guessed or
//-1 if the letter isn't in the word
int CompareLetter(char array[], char guess, int numLetters);
//tells the player if they won the game or not
void wonGame(int theSame);
//updates the word in progress array with correct guesses
void updateWIP (char array[], char guess, int result);
main()
{
//declare variables
FILE *fp;
int i;
int x;
char wtbg[S] = {'\0'};
char gl[S] = {'\0'};
char wip[S] = {'\0'};
char guess = ' ';
int numguess = 0;
int numLetters = 0;
int theSame = 0;
int wresult = 0;
//displays instructions for user
Instructions();
//get word from file
fp = fopen ("words.txt", "r");
fscanf(fp,"%s", wtbg);
//copy length of wtbg to wip array
numLetters = strlen(wtbg);
DisplayArray(wtbg);
while (numguess != 6)
{
//printf("GUESS=%d", guess);
//display wip
printf("GUESS THIS WORD:\n");
for (i = 0;i < numLetters; i++)
{
wip[i] = '*';
//printf("%c", wip[i]);
}
wip[i] = '\0';
guess = tolower(GuessLetter());
gl[numguess] = (guess);
printf("\nLetters guessed so far: ");
DisplayArray(gl);
DisplayArray(wip);
wresult = CompareLetter(wtbg, guess, numLetters);
printf("wresult=%d", wresult);
updateWIP(wip, guess, wresult);
//theSame = CompareArray(wtbg, wip, numLetters);
//printf("\nAre they the same array? %d", theSame);
//printf("NUM LETTERS = %d", numLetters);
//update number of guesses
//wresult = 0;
numguess++;}
//printf("GUESS=%d", guess);}
return 0;
}
//displays instructions for user
void Instructions()
{
printf("WELCOME TO THE ULTIMATE GAME OF HANGMAN!\n\n");
printf("PLEASE TAKE A LOOK AT THE FOLLOWING RULES/INSTRUCTIONS!\n\n");
printf("You will have the opportunity to guess a word.\n\n");
printf("Guess the letters one at a time.\n\n");
printf("You can have upto six wrong guesses.\n\n");
printf("The game ends when either you have guessed:\n");
printf("--all the letters in a word\n");
printf("--guessed wrong six times\n\n");
printf("LET THE GAMES COMMENCE...\n\n");
}
//displays character arrays
void DisplayArray(char array[])
{
printf("%s\n", array);
}
//prompts user to enter a letter and stores it in guess array
char GuessLetter()
{
char guess;
printf("\nPlease enter a letter:");
scanf(" %c", &guess);
return guess;
}
//compares arrays to see if they match or not
int CompareArray(char arraya[], char arrayb[])
{
int theSame;
theSame = strcmp(arraya,arrayb);
return theSame;
}
//function that returns the index of the letter that the user has guessed or
//-1 if the letter isn't in the word
int CompareLetter(char array[], char guess, int numLetters)
{
int i;
for (i = 0;i < numLetters; i++)
{
//printf("numLetters=%d", numLetters);
if(array[i] == guess) {
return i;
}
} //printf("numLetters=%d", numLetters);
return -1;
}
//tells the player if they won the game or not
void wonGame(int theSame)
{
if (theSame == 0)
{
printf("\nCONGRATS...YOU WON THE GAME!!!");
}
else if (theSame == 1)
{
printf("\nSORRY YOU DIDN'T WIN LOOSER...");
}
}
//updates the word in progress array with correct guesses
void updateWIP (char array[], char guess, int result)
{
printf("GUESS=%c", guess);
printf("WRESULT=%d", result);
printf("WIP ARRAY%s\n", array);
if (result !=-1)
array[result] = guess;
}