MENSA puts out these weekly word puzzles. For whatever reason I decided to try and write something which would solve them. The puzzles take the following format:
A_I_T_C_A_I_
... where the underscore characters signify blanks that you have to fill in to find the word in the puzzle. Simple concept, fun to try and solve in your head. But I am bored at work, so here we are.

I have really only started the process of getting my ideas down into code, and since this isn't for work or any assignment, I wanted to get some input from you guys on the problem I'm having. I have a char * that I pass into a GetWord() function. This GetWord() function prompts the user for the length of the word puzzle and then asks the user to input the word puzzle in the above format, with underscores indicating blanks to be filled in.

Unfortunately, when I try to print the word puzzle in my main(), I get a bunch of garbage, whereas it prints perfectly in the GetWord() function. I'm thinking it's a problem with 1) how I'm utilizing malloc() inside the GetWord() function or 2) how I'm utilizing the char * back in the main().

Here is the relevant code:
Code:
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

void GetWord(char *word, int *unknowns, int *word_length, int *num_unknowns);

int main(void)
{
	int word_length;		/**< Length of the word puzzle. */
	int num_unknowns;		/**< Number of unknown letters in the puzzle. */
	char *word;				/**< The word puzzle. */
	int *unknowns;			/**< An array containing the locations of unknown letters. */
	
	GetWord(word, unknowns, &word_length, &num_unknowns);
	
	printf("The puzzle to be solved is '%s', %d letters long.\n", word, word_length);
	printf("There are %d unknowns.\n", num_unknowns);
	
	
	printf("Press ENTER to exit.");
	fflush(stdout);
	scanf("%*c");
	
	return 0;
}

void GetWord(char *word, int *unknowns, int *word_length, int *num_unknowns)
{
	int j = 0;
	int k = 0;
	
	*word_length = 0;
	*num_unknowns = 0;
	
	while (*word_length <= 0)
	{
		printf("Please enter the total number of letters in the word: ");
		fflush(stdout);
		scanf("%d%*c", word_length);
		
		if (*word_length <= 0)
		{
			printf("Please enter a valid word length.\n");
			fflush(stdout);
		}
		else
		{
			printf("You've input a word length of %d. Thank you.\n", *word_length);
			fflush(stdout);
			word = malloc(sizeof(char) * (*word_length + 1));
			unknowns = malloc(sizeof(char) * (*word_length + 1));
		}
	}
	
	printf("Please enter the word puzzle to solve with length %d.\n", *word_length);
	printf("Enter a _ character for each blank letter in the word.\n");
	fflush(stdout);
	
	scanf("%s%*c", word);
	strcat(word, "\0");				/**< Append a null to the end of the word puzzle. */
	
	for (k = 0; k < *word_length; k++)
	{
		/** If we have a blank space in the word puzzle ... */
		if(word[k] == '_')
		{
			/** Add the current index into the 'unknowns' array for later. */
			unknowns[j] = k;
			/** Increment the number of unknowns. */
			*num_unknowns = (*num_unknowns) + 1;
			/** Increment the index of the 'unknowns' array. */
			j++;
		}
	}
	/** Place a '-1' at the end of the 'unknowns' array to signify the end of the array. */
	unknowns[j] = -1;
	
	printf("The puzzle to be solved is %s. There are %d unknowns.\n", word, *num_unknowns);
}
And the output:
Code:
Please enter the total number of letters in the word: 12
You've input a word length of 12. Thank you.
Please enter the word puzzle to solve with length 12.
Enter a _ character for each blank letter in the word.
A_I_T_C_A_I_
The puzzle to be solved is A_I_T_C_A_I_. There are 6 unknowns.
The puzzle to be solved is 'Y[]Ã1Àƒ=ä@', 12 letters long.
There are 6 unknowns.
Press ENTER to exit.
... where the first "The puzzle to be solved is..." is found inside GetWord(), and the second is found back inside main().

I haven't even begun to tackle the 'unknowns' array, but I can tell you that it basically just contains garbage at this point despite my attempts to populate it. Any general guidance on how to tackle the program as a whole is also welcome. Let me know if you have any ideas on the problem presented here, most importantly.

Thanks,
Jeremy

P.S. The answer to the puzzle is aristocratic.