I'm fairly new at C and I was wondering how to set all elements in an array of pointers to null. I created a structure that includes a pointer to an array of pointers, and I'd like to set all of those pointers to null.
Here is the structure:
typedef struct
{
char **array;
int size, capacity;
} ArrayList;
And here's where I try to create an array of pointers and initialize them to null:
ArrayList *createArrayList(int length)
{
int i;
ArrayList* strArray = malloc(sizeof(ArrayList));
for(i=1; i<length; i++)
{
strArray->array[i] = NULL;
}
return strArray;
}
Unfortunately this yields a segmentation fault. Any help would be greatly appreciated.