I am trying to split a string into tokens, but somewhat recursively. I am trying to parse:
"content=0&website=Google"
so that I have a way to output the parameters and values. If I try strtok , I will eventually destroy the string that I want to parse twice. So I tried
char *contents = "content=0&website=Google" char arg[100]; char value[100]; sscanf(contents, "%s&%s", arg, value);
as a first pass, hoping to parse arg again, but it fails, and arg contains the entire string. I tried using the "%s\&%s" thinking & was a reserved word, but no luck there.
Help!
Edit:
This was my strtok hack:
static void readParams(char * string, char * param, char * value) { printf("This is the string %s\n",string); char * splitted = strtok (string,"="); while (splitted != NULL) { printf("This is the string %s\n",splitted); splitted = strtok (NULL, "=");
but it does not work, because the broken strtok at the end becomes gobbldygook.
source share