I am trying to allocate a array of char*'s in C. I know the number of columns in advance, but not the rows and I want to allocate the rows as and when needed.
I tried to use:
char *(*data)[NUMCOLS]; //declare data as pointer to array NUMCOLS of pointer to char
data = malloc(sizeof(char*));
now, the above line should allocate for data[0] ... correct? then, I must be able to use the row like
data[0][1] = strdup("test");
.
..
data[0][NUMCOLS-1] = strdup("temp");
I am getting seg fault. I am not able to understand what is wrong here. can anyone please help.