【发布时间】:2016-11-12 09:30:00
【问题描述】:
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;
}
我的函数getUserWord 通过传递一个字符串来完成它的任务。从我在线阅读的内容来看,char *baseWord = getUserWord(); 是将字符串分配给主函数中的变量的唯一方法。我不知道为什么这是有效的,我什至不确定这在内存中做了什么。以下是对我有意义的内容。为什么这行不通?
char baseWord[21];
baseWord = getUserWord();
【问题讨论】: