I could still be wrong here, iv'e only been learning C for around 3 months, but i copied it into another char array first then pointed to that as strtok_r takes a pointer for its first argument? char copiedstr;, or have I misunderstood something,
I don't think you are using strtok_r the right way. The third argument is supposed to be:
s3 : Is a value-return parameter used by strtok_r() to record its progress through s1.
You aren't using it like that.
char *saveptr1, *saveptr2, *saveptr3, *saveptr4, *saveptr5;
str1 = sstring;
cmd = strtok_r(str1, &delim, &saveptr1);
arg1 = strtok_r(str1, &delim, &saveptr2);
str1 = saveptr2;
arg2 = strtok_r(str1, &delim, &saveptr3);
str1 = saveptr3;
arg3 = strtok_r(str1, &delim, &saveptr4);
str1 = saveptr4;
arg4 = strtok_r(str1, &delim, &saveptr5);
According to the docs:
To get the first token from s1, strtok_r() is called with s1 as its first parameter. Remaining tokens from s1 are obtained by calling strtok_r() with a null pointer for the first parameter.
You aren't calling strtok_r with NULL as the first parameter. You are somehow combining both ideas.
I just read up a little on regex's and the search and match functions are a little out of context, maybe I was a bit hasty when i quoted "should do the trick"
is the only documentation available included in the link you posted?
There's lots of documentation on regular expressions, and examples in the library. Perhaps if you showed an example of the incoming string, and what you expect to extract from it (by example). I found your description:
... it first checks the next character in the original array to see if its a '"' (quote) or not, if its a quote it sets the delimiter as a quote and calls strtok_r, and places the quoted string into 1 argument, then i change the delimiter back to a space and before calling strtok_r again it checks if the next character is an quote ...
... confusing. I can't visualize what you are passing in, and what you expect to get out.