void printInstructions();
char *getUserWord();
int main()
{
printInstructions();
char *baseWord = getUserWord();
printf("%s", baseWord);
return 0;
}
void printInstructions()
{
printf(" Instructions: \n"
"===================================================================\n"
"= This program is a hangman game. =\n"
"= The first user will enter the name to be guessed =\n"
"= After that, the second user will guess the letters of the word =\n"
"= the second user will loose if they have three strikes =\n"
"===================================================================\n");
return;
}
char *getUserWord()
{
static char str[20];
scanf("%s", str);
return str;
}
My function getUserWord accomplishes its task by passing a string. From what I read online char *baseWord = getUserWord(); was the only way to assign the string to a variable within the main function. I do not know why this is working and I am not even sure what this is doing in memory. Below is what would make sense to me. Why would this not work?
char baseWord[21];
baseWord = getUserWord();