I am going to add an answer to Adam here because it probably won't fit in the comment. Adam is absolutely right. I suspect your generate_fields function, however, may actually receive 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 the corresponding free function, which I will leave for brevity. You can see what happens - we pass the number of fields and the size of the field. Change this as necessary. Another option is to generate fields that return to the routine that he called from the size of the array. I would do something like this:
int generate_fields(char** options) { int num_fields = 0;
And you call from the main, like this:
int main() { int sizeofarray = 0; char** fields; sizeofarray = generate_fields(fields);
Or, if you do not like these notations, you can always stick to what you had:
char** generate_fields(int* size)
As a function prototype (return the parameters this time and make size= somewhere in the code and call from the main one, like this:
int sizeofarray = 0; char** options; options = generate_fields(&sizeofarray);
Hope that gives you a few more ideas, Adam, feel free to edit all / all of this in your answer, if necessary, anyway from your answer.
user257111
source share