char (*data)[LEN]; // where LEN is known at compile time ... data = malloc(sizeof *data * rows); // where rows is determined at run time ... strcpy(data[i], some_name); ... printf("name = %s\n", data[i]); ... free(data);
Note that data
is a pointer type, not an array type ( data
is a pointer to an array of the LEN
char
element). A malloc
call will dynamically allocate enough memory to hold rows
of LEN
length arrays. Each data[i]
will be of type char [LEN]
.
source share