我從一本書教自己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]
不知道是什麼這個問題......我試圖查找如何使一個字符串數組,但沒有運氣
任何幫助將非常感激,
山姆
嘗試研究一下數組http://pw1.netcom.com/~tjensen/ptr/pointers.htm。 – 2013-03-01 16:01:48
順便說一下 - 'char word1 [6] =「蓬鬆」 - 「蓬鬆」實際上是7個字符。在C中,一個字符串以'\ 0'結尾 - 佔用一個額外的字符。 – ArjunShankar 2013-03-01 16:03:34
'const char * arr [] = {「literal」,「string」,「pointer」,「array」};',並注意** const **。 – WhozCraig 2013-03-01 16:03:37