Hi, I am programming in C ( not C++ ) and I want to dynamicly allocate memory for an array of string pointers.
I need to do this because I am using the execv unix system call which must take an array of char *.
When I do the following code :
char *command[3];
command[0] = "ls";
command[1] = "-r";
command[2] = NULL;
execv(my_strcat("/bin/", command[0]), command);
Everything goes fine, but when my program runs it does not know which command the user will enter and how many parameters it will have. So I cannot specify that char *command will be char *command[3] because there could be 0, 5, 2, etc. parameters.
I have tried
char *command;
command = (char *) malloc(numberOfParam * sizeof(char *));
To dynamicly create the command array to the appropriate number of param but when I later try to do something like :
command[0] = "ls";
command[1] = "-r";
command[2] = NULL;
It gives me this error :
error: invalid conversion from `const char*'' to `char''
What is the proper way to dynamicly create an array of char * ?
Thank you in advance for any help you can provide.