title: hangman: beginner in C
body: <p>I can't seem to figure out why my program won't end the game when the user guesses the all the letters. I know the problem is in the play( ) function. Any pointers on what to change in the play function or whatever is causing this problem?</p>
  
  <pre><code>#include    &lt;stdio.h&gt;
  #include    &lt;string.h&gt;
  #include    &lt;ctype.h&gt;
  // MAXWORD, which will be the max word length 
  #define     MAXWORD     10
  // INCORRECT_GUESSES, which will be the max guesses
  #define     INCORRECT_GUESSES   5
  
  /* Prototypes */
  
  // Fills theArray with howMany copies of theLetter
  void    fill_array( char *theArray, int howMany, char theLetter );
  
  // Get char from player, checks the letter, shows progress so far
  int     get_letter( char *theWord, char *soFar );
  
  // Check if letter is in word, updates progress so far
  int     letter_in_word( char *theWord, char *soFar, char theLetter );
  
  // Convert the word to lowercase
  void    lower_string( char *someWord );
  
  // Play one game
  void    play( char *theWord );
  
  /* Function definitions */
  
  int main( )
  {
      char theWord [ MAXWORD ];
      FILE*   word;
      word = fopen( "guesswords.txt", "r" );
  
      if ( word == NULL )
      {
          printf( "No input file found..........\n" );
          return -1;
      }
      printf("Want to play a game?\n");
      fscanf( word, "%s", theWord );
  
      lower_string( theWord );
  
      play( theWord );
      fprintf( word, "%s", theWord);
      fclose( word );
      return 0;
  }
  
  // Get char from player, checks the letter, shows progress so far
  int get_letter( char *theWord, char *soFar )
  {
      char theLetter;
      printf("\nPlease enter a letter: ");
      scanf( " %c", &amp;theLetter );
      theLetter = tolower(theLetter);
  
      letter_in_word( theWord, soFar, theLetter );
  
      return theLetter;
  }
  
  // Fills theArray with howMany copies of theLetter
  void fill_array( char *theArray, int howMany, char theLetter )
  {
      int i;
      for( i=0; i&lt;howMany; i++ )
      {
          theArray[i]= theLetter;
          *(theArray + i) = theLetter;
          *theArray = theLetter;
      }
      theArray[howMany] = '\0';
  }
  
  // Check if letter is in word, updates progress so far
  int letter_in_word( char *theWord, char *soFar, char theLetter )
  {
      int i;
      int num=0;
      int len = strlen(theWord);
  
      for( i=0; i&lt;len; i++)
      {
          if (theWord[i] == theLetter )
          {
              soFar[i] = theLetter;
              num++;
          }
      }
      if (num == 0)
      {
          printf( "\nSORRY! your letter is not in the word\n" );
          printf("%s\n", soFar);
          return 0;
  
      }
      else if (num&gt;0)
      {
          printf( "\nCongratz! your letter was in the word\n" );
          printf("%s\n", soFar);
          return 1;
      }
  }
  
  // Convert the word to lowercase
  void lower_string( char *someWord )
  {
      int i, cha;
      int len = strlen( someWord );
      for( i=0; i&lt;len; i++ )
      {
          cha = someWord[i];
          cha = tolower(cha);
          someWord[i] = cha;
      }
  }
  
  // Play one game
  void play( char *theWord )
  {
      int i;
      int len = strlen(theWord);
      int guess = INCORRECT_GUESSES;
      int result = 0;
      char soFar[MAXWORD];
      fill_array( soFar, len, '*');
      printf( "Guess this word: %s\n", soFar ); 
  
      for( i=0; i&lt;INCORRECT_GUESSES; i++ ) 
      {
          guess = INCORRECT_GUESSES - (i+1);
          get_letter( theWord, soFar );
  
          if(get_letter&lt;0)
          {
              printf( "\nYou have %d guesses left\n", guess);
          }
          else
          {
              printf( "\nYou have guessed all the letters! You have won!" );
              return;
          }
  
          if( i == INCORRECT_GUESSES-1)
          {
              printf( "\nSorry, you're out of guesses\nBetter luck next time!\n" ); 
          }
      }
  }
  </code></pre>