I'm going to add to Adam's answer here, because this probably won't fit in a comment. Adam is completely right. I suspect your generate_fields function, however, perhaps actually gets input from the user, I'm not sure. In any case, there are two ways to approach this:
char ** generate_fields(char *, int num_fields, int size_of_field)
{
char ** options = malloc(num_fields*sizeof(char *));
for(int i = 0; i < num_fields; i++)
options[i] = malloc(size_of_field);
return options;
}
and a corresponding free function, which I'll leave out for brevity. You can see what's going on - we're passing in the number of fields and the field size. Change this around as you need. The other option is to have generate fields pass back to the routine it's called from the size of the array. I'd do something like this:
int generate_fields(char** options)
{
int num_fields = 0;
// somewhere here we get num_fields
options = malloc(num_fields*sizeof(char *));
for(int i = 0; i < num_fields; i++)
options[i] = malloc(size_of_field);
return num_fields;
}
And you call from main like this:
int main()
{
int sizeofarray = 0;
char** fields;
sizeofarray = generate_fields(fields);
Or if you dislike that notation, you can always stick to what you had:
char** generate_fields(int* size)
As the function prototype (return options this time and do size=
somewhere in the code and call from main like this:
int sizeofarray = 0;
char** options;
options = generate_fields(&sizeofarray);
Hope that gives you some more ideas, Adam, feel free to edit any / all of this into your answer as appropriate, it comes from your answer anyway.