I thought hangman was played in a way where if you guessed a letter that's in the word then all occurences of that letter in the word are printed:
Code:
/* pseudocode, may not work
** and definitely won't be pretty
*/
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#define CHANCES 10
int main ( void )
{
size_t i,
tries = 0;
char *word = "mouse",
mask[] = "-----",
ch;
puts ( mask );
printf ( "Hangman\nChoose a letter: " );
while ( ( ch = getchar() ) != EOF ) {
for ( i = 0; i < strlen ( word ); i++ ) {
if ( word[i] == ch )
mask[i] = word[i];
}
tries++;
if ( strcmp ( mask, word ) == 0 ) {
printf ( "You win!\n" );
return EXIT_SUCCESS;
}
else if ( tries >= CHANCES ) {
printf ( "You lose\nPlease deposit 25 cents and try again\n" );
return EXIT_SUCCESS;
}
while ( getchar() != '\n' );
puts ( mask );
printf ( "Please choose another letter: " );
}
return EXIT_SUCCESS;
}
-Prelude