I'm making a hangman and everything works fine if you win, but if you lose it doesn't print the word it was.
I was debugging it and I found that in one of the last iterations the first character is changed to '\000' so that is why it doesn't print, but I don't understand why because there is no line where the array word is changed.
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
#include <string.h>
#define VOCABULARY_SIZE 8
#define MAX_STRING 32
#define MAX_GUESS 6
int random_number(int a, int b)
{
    return a + rand() % (b - a + 1);
}
int main()
{
    //random word selection
    srand((unsigned)time(NULL));
    const char VOCABULARY[VOCABULARY_SIZE][MAX_STRING] = {"vehicle", "building", "shirt", "pencil", "batman", "dromedary", "peach", "hangman"};
    char word[MAX_STRING];
    int i;
    i = random_number(0, VOCABULARY_SIZE - 1);
    strcpy(word, VOCABULARY[i]);
    //user word
    int guesses = 0, length = strlen(word);
    char letters[MAX_GUESS+1];
    char input[MAX_STRING];
    char temp_char;
    char temp_input[MAX_STRING];
    do
    {
        printf("\nYour entered letters are: ");
        printf("%s", letters);
        printf("\nYour letters found are: ");
        for (int j = 0; j < length; j++)
        {
            if (word[j] == input[j])
            {
                printf("%c", word[j]);
            }
            else
            {
                printf("_");
            }
        }
        printf("\n%d-letter word. %d out of %d failures. Enter a letter: ", length, guesses, MAX_GUESS);
        scanf(" %c", &temp_char);
        letters[guesses] = temp_char;
        letters[guesses+1] = '\0';
        for (int j = 0; j < length; j++)
        {
            if (word[j] == temp_char)
            {
                input[j] = word[j];
            }
        }
        guesses++;
        printf("\nWhat is the word to guess? ");
        scanf(" %s", temp_input);
    } while ((strcmp(input, word) != 0 && strcmp(temp_input, word) != 0) && guesses <= MAX_GUESS);
    if (strcmp(input, word) == 0 || strcmp(temp_input, word) == 0)
    {
        printf("\nCongratulations, the word was %s!", word);
    }
    else
    {
        printf("\nBetter luck next time... The word was %s", word);
    }
}
 
     
    