I got the following problem:
I have an array of char pointers
char *opts[] = { "-a", "--append", "-b" };
and a command name stored in
char cmd[] = "ls";
Now I need to compute all possible combinations, which I've done using the GNU Scientific Library and execute the command with the compute combinations.
The problem I have is how to compute the amount of memory I need for the char * getting passed to system().
Here's my first try:
int length = strlen(cmd) * sizeof(char);
for (int i = 0; i < 3; ++i) {
length += strlen(opts[i]) * sizeof(char);
}
Well, it worked, but I sense that this is not the right/best solution. Can't I cast the two-dimensional-array to a flat one-dimensional-array and get the size of it (if I'm not wrong, the are no multidimensional arrays in C, C only mimics them).