You're going to need to know how many strings are contained in the array, either by adding a count member to the struct or by using a NULL sentinel value. The following examples use the NULL sentinel:
Allocating and initializing:
STRUCT s;
s.p = malloc(sizeof *s.p * (number_of_strings + 1));
if (s.p)
{
size_t i;
for (i = 0; i < number_of_strings; i++)
{
s.p[i] = malloc(length_of_ith_string + 1);
if (s.p[i])
strcpy(s.p[i], ith_string);
}
s.p[i] = NULL;
}
for appropriate values of number_of_strings
, length_of_ith_string
, and ith_string
.
Accessing/printing:
for (i = 0; s.p[i] != NULL; i++)
printf("String %d: %s\n", i, s.p[i]);
Deallocating:
for (i = 0; s.[i] != NULL; i++)
free(s.p[i]);
free(s.p);