The program is long so I can't really post everything so I'm giving the abridged version that will hopefully be relevant to others too.
Right now the program uses this data structure in main:
char b[100];
gets(b);
char arr[5][100];
sscanf(b, "%s", arr[0]); //user enters a query in the command line
//initializes statement based on what arr[0] is
//in this case, calls myFunction
I want to use malloc to make the char array of unknown size now instead of what I have now. There are some examples online on how to make a 2D array using malloc but I don’t know if the type of implementation I use will mess up with my already made function that follows this structure:
void myFunction(char *b, char *argv[]) {
char arr[5][100];
sscanf(b, "%s %s", arr[0], arr[1]);
//do stuff to the array like strcpy(arr[0],argv[1]);
// or FILE *f = fopen(arr[0], "r");
}
Would I just initialize malloc
in main
and do the same in the function as well? I feel like if I do that, playing around with the array in the function will no longer be as simple as I’ve already done it since I'm dealing with dynamic memory now.