Need a little help with hangman
So, I've gotten the basic program down. Gotten the thing to run. It loads up the program, loads up the instructions, then puts the blanks properly with the corresponding word. Well, it asks you to guess a letter. I enter a letter (the word in the file I created is doggy) and when I press enter, it fails. Not sure why, I think that it's running perfectly. Any help would be much appriciated!
Code:
#include <stdio.h>
#include <string.h>
#include <ctype.h>
#define MAX_SIZE = 20;
#define MAX_LETTERS = 26;
#define MAX_GUESS = 6;
void instruct();
int play_again();
void initialize();
int letter_check(char c);
int won();
char word_to_guess[20], word_in_prog[20], letters_guessed[26];
int guess;
int main()
{
int i;
char c;
FILE *in_file;
in_file = fopen("wordlist.txt","r");
do {
if( feof(in_file) )
rewind(in_file);
fscanf(in_file, "%s", word_to_guess);
for(i = 0; i < strlen(word_to_guess); i++) {
word_to_guess[i] = tolower(word_to_guess[i]);
}
initialize();
instruct();
do {
printf("\n Number of tries left : %d", guess);
printf("\n %s", letters_guessed);
printf("\n Word to guess : ");
for(i = 0; i<strlen(word_in_prog); i++)
printf("%c ", word_in_prog[i]);
printf("\n Please guess a letter : ");
scanf("%c", c);
c = tolower(c);
letter_check(c);
if( !letter_check(c) )
guess--;
} while( guess > 0 || won() );
if( guess == 0 )
printf("\n You LOSE!");
} while(play_again());
fclose(in_file);
}
void instruct()
{
printf("\n Hangman v6.9");
printf("\n To play, guess a letter. You get 6 wrong tries, then your man gets hung. Is that a bad thing?");
}
int play_again()
{
char c;
printf("\n Would you like to play again? [y/n]");
scanf("%c", &c);
tolower(c);
if(c == 'y')
return 1;
else
return 0;
}
void initialize()
{
int i;
guess = 6;
for(i=0; i<26; i++) {
letters_guessed[i] = '-';
}
for(i=0; i<strlen(word_to_guess); i++) {
word_in_prog[i] = '_';
}
}
int letter_check(char c)
{
int i, flag = 0;
for(i = 0; i<strlen(word_to_guess); i++) {
if(c == word_to_guess[i]) {
flag = 1;
word_in_prog[i] = c;
}
}
return flag;
}
int won()
{
int flag = 0;
if(strcmp(word_to_guess, word_in_prog)) {
printf("\n You've WON! %s is the right answer!", word_in_prog);
flag = 1;
}
return flag;
}
Again, any help on this would be awesome!