SIMEL
SIMEL

Reputation: 8941

creating an array of strings with predefined length in C

I want to make an array of 20 strings (char*) where each of them is allocated automatically length of MAXLENGTH

will by saying:

char *string_arr[MAXLENGTH][20];

I'll be able to address each string as string_arr[i] where 0=<i<20 and more importantly, will I be able to put things into string_arr[i] without dynamically allocating memory, e.g:

strcpy(string_arr[2],"some string");

?

Upvotes: 1

Views: 616

Answers (1)

sukru
sukru

Reputation: 2259

Instead of

char *string_arr[MAXLENGTH][20];

Say:

char string_arr[20][MAXLENGTH];

You also probably want to say MAXLENGTH+1 for null termination.

Upvotes: 5

Related Questions