How to create an array of strings in C?

arrays, c, string

Solution

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.

Problem

I'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

Original source

Related problems