这个问题在这里已经有了答案:
我如何在C中创建一个字符串数组? 14个答案我从一本书教自己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]不知道是什么问题...我试图查找如何创建一个字符串数组,但没有运气
任何帮助都感激不尽,
山姆
This question already has an answer here:
How do I create an array of strings in C? 14 answersI'm teaching myself C from a book and I am trying to create a crossword puzzle. I need to make an array of strings but keep running into problems. Also, I don't know much about array...
This is the piece of the code:
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*/But I keep getting the message:
crossword.c:20:16: warning: assignment makes integer from pointer without a cast [enabled by default]Not sure what is the problem...I have tried to look up how to make an array of strings but with no luck
Any help will be much appreciated,
Sam
最满意答案
words_array[0]=word1;
word_array[0]是一个char ,而word1是一个char * 。 你的角色无法持有地址。
一串字符串可能看起来像这样:
char array[NUMBER_STRINGS][STRING_MAX_SIZE];如果你想要一个指向你的字符串的指针数组:
char *array[NUMBER_STRINGS];接着:
array[0] = word1; array[1] = word2; array[2] = word3;也许你应该读这个 。
words_array[0]=word1;
word_array[0] is a char, whereas word1 is a char *. Your character is not able to hold an address.
An array of strings might look like it:
char array[NUMBER_STRINGS][STRING_MAX_SIZE];If you rather want an array of pointers to your strings:
char *array[NUMBER_STRINGS];And then:
array[0] = word1; array[1] = word2; array[2] = word3;Maybe you should read this.
更多推荐
发布评论