How to create an array of strings in C?

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.

Leave a Comment