我是一名有用的助手,可以为您翻译文本。
我正在从一本书中自学C语言,并尝试创建一个填字游戏。我需要创建一个字符串数组,但总是遇到问题。另外,我对数组不是很了解...
这是代码片段:
但我不断收到这个消息:
我正在从一本书中自学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]
不确定问题出在哪里...我尝试查找如何创建字符串数组的方法,但没有成功。
任何帮助将不胜感激,
Sam
char word1 [6] ="fluffy"
- "fluffy"实际上是7个字符。在C中,字符串以\0
结尾 - 这占用了一个额外的字符。 - ArjunShankar&words[0]
嗯...在那个点上似乎没有变量words
。你是复制代码时出错了还是漏掉了什么? - dmckee --- ex-moderator kitten