Code:
#include <stdio.h>
#include <string.h>
int main()
{
char word[] = {"book"};
char gotIt[40] = { ' ' }; //spaces
char j;
int guess, i, len;
for(guess = 0; guess < 8; guess++) {
printf("\nGuess a letter: ");
scanf(" %c", &j);
len = strlen(word);
gotIt[len] = '\0';
for(i=0; i<len; i++)
{
if(j == word[i] && j != gotit[i]) {
gotIt[i] = word[i];
printf("%s", gotIt);
if((strcmp(word, gotIt) == 0)
printf("You have won! Congratulations ");
}
else
printf("Guess again, there are no %c's \n", j);
}
printf("\n\n\t\t Press enter when ready");
getchar(); //holds the console window open
return(0);
}
I haven't compiled the above, but it should give you a starting point
For an upgraded version, I suggest:
1) Download a small file of common words, from the net (Google "word list").
2) Use a random number to choose the special word for each game, from that list.
3) You need a text figure of a guy appearing more and more complete, with every
failed guess. After 8 (or so) guesses, if all the letters have not been correctly guessed, his last body part appears and he gets hanged.
That's the fun of hangman, right there. Otherwise, it's like "Wheel of Fortune" - boring.