I fixed the blatant errors, but the program still doesn't work quite as it should. That part is up to you
Don't use void main, that makes your entire program undefined. Whenever you use scanf to read string data you'll want to clear the input buffer with a loop, or just avoid using scanf to read string data
Code:
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
void intro(void);
void get_word(char * word);
char get_letter(void);
void check_letter(char * word, char c,int * mistakes);
int main(void)
{
char word[10], guess;
int miss = 0;
intro();
get_word ( word );
system("CLS");
while (miss < 3) {
guess = get_letter();
check_letter(word, guess, &miss);
}
return 0;
}
void intro(void)
{
printf(" ********************************************\n");
printf("Hangman by Gearoid Donnellan\n");
printf(" ********************************************\n\n");
printf("Welcome to my hangman game. Player 1 enters a word then\n");
printf("Player 2 must enter their guesses. Three wrong guessses\n");
printf("and you lose!\n\n");
}
void get_word(char * word)
{
printf("Player 1, please enter a word >");
fgets ( word, sizeof word, stdin );
}
char get_letter(void)
{
char c;
printf("\n\nPlease enter a letter >");
while ( getchar() != '\n' );
scanf ( "%c", &c );
return c;
}
void check_letter(char word[9], char c, int *mistakes)
{
unsigned i = 0, m = 0, n = 0;
do {
if (word[i] != c) {
printf("*");
m += 1;
}
else {
printf("%c", c);
n += 1;
}
i += 1;
} while(i <= strlen(word));
*mistakes = m;
printf("You uncovered %d letters\n\n", n);
}
-Prelude