title: Split C string into tokens using sscanf
body: <p>I'm trying to split a string into tokens but somewhat recursively. I am trying to parse:</p>
  
  <pre><code>"content=0&amp;website=Google"
  </code></pre>
  
  <p>so that I have a way to take out the parameters and values. If I try <code>strtok</code> I end up destroying the string I want to parse twice. So I tried</p>
  
  <pre><code>char *contents = "content=0&amp;website=Google"
  char arg[100];
  char value[100];
  sscanf(contents, "%s&amp;%s", arg, value);
  </code></pre>
  
  <p>as a first pass, hoping to parse <code>arg</code> again, but it fails, and <code>arg</code> contains the entire string. I tried using <code>"%s\&amp;%s"</code> thinking <code>&amp;</code> was a reserved word, but no luck there.</p>
  
  <p>Help!</p>
  
  <p>Edit:</p>
  
  <p>This was my strtok hack:</p>
  
  <pre><code>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, "=");
          // Then do some saving to param and value
      }
  }
  char * splitted = strtok (contents,"&amp;");
  int counter = 0;
  
  while (splitted != NULL)
  {
      char * t_str = strdup(splitted);
      readParams(t_str, param, value);
      splitted = strtok (NULL, "&amp;");
  }
  </code></pre>
  
  <p>but it doesn't work because splitted's <code>strtok</code> at the end becomes gobbldygook.</p>