When your question is answered use !solved to mark the question as resolved.
Remember to ask specific questions, provide necessary details, and reduce your question to its simplest form. For tips on how to ask a good question run !howto ask.
14 messages · Page 1 of 1 (latest)
When your question is answered use !solved to mark the question as resolved.
Remember to ask specific questions, provide necessary details, and reduce your question to its simplest form. For tips on how to ask a good question run !howto ask.
I think the best option is to have an output parameter
Basically take an array of char* as arguments then write the data to that instead of creating a local array
Then it is the caller's responsibility to either create an array that can hold all the pointers and pass that to your function
Something like this?
char* getArguments(char* argsList, char* args) {
int i = 0;
while (strtok(argsList, " ")) {
i = i + 1;
args[i] = strtok(NULL, " ");
}
return args;
}
That does have the warning: warning: assignment makes integer from pointer without a cast [-Wint-conversion]
args[i] = strtok(NULL, " ");
char **args
Also you can return void, or some other meaningful value, like how many tokens parsed
Got it!
And to call it you'd do something like this?
char *string = "this is a string";
char* args[10];
getArguments(string, *args);
I'd say args without the *
Thank you and let us know if you have any more questions!