【发布时间】:2016-04-03 06:30:40
【问题描述】:
int main(){
char inputType[5] = "hello you"; //a string
char *word[5]; //a string that will contain 4 character + the null
word = get_word(inputType);
return 0;
}
char *get_word(char inputType[]){ //inputType is a string
char *array[2]; //an array that will store ["hello", "you"]
// got correct code to make it ["hello", "you"]
return array[1] //want to return "you"
}
我收到此错误消息:
Error: word = get_word (inputType) assingment to expression with array Type------------------------------
问题:
- char inputType[5] 是否声明了一个字符串?
- char
*word[5]与inputType[5]之间的区别 - 错误消息的原因。
【问题讨论】:
-
什么是
get_word()? -
同样在
char inputType[5] = "hello you";,您在这里分配了超过 5 个字符。 -
get_word 是函数
-
好的,因为首先你写了
*word()感谢编辑 -
get_word()返回一个字符,而word是一个字符串。所以你可以运行:word = get_word(inputType);,因为类型不兼容。