【发布时间】:2013-02-16 04:37:35
【问题描述】:
我正在从一本书中自学 C,并且我正在尝试创建一个填字游戏。我需要制作一个字符串数组,但不断遇到问题。还有,我对数组不太了解……
这是一段代码:
char word1 [6] ="fluffy", word2[5]="small",word3[5]="bunny";
char words_array[3]; /*This is my array*/
char *first_slot = &words_array[0]; /*I've made a pointer to the first slot of words*/
words_array[0]=word1; /*(line 20)Trying to put the word 'fluffy' into the fist slot of the array*/
但我不断收到消息:
crossword.c:20:16: warning: assignment makes integer from pointer without a cast [enabled by default]
不知道是什么问题...我试图查找如何制作字符串数组但没有运气
任何帮助将不胜感激,
山姆
【问题讨论】:
-
尝试更多地研究数组pw1.netcom.com/~tjensen/ptr/pointers.htm。
-
顺便说一句 -
char word1 [6] ="fluffy"- “蓬松”实际上是 7 个字符。在 C 中,字符串以\0结尾 - 它占用一个额外的字符。 -
const char* arr[] = { "literal", "string", "pointer", "array"};,并注意 const。 -
&words[0]呃...此时您似乎没有变量words。您是否在复制代码时出错或遗漏了什么? -
@teahupoo 谢谢我去看看!