title: reading the remainder of a string with sscanf
body: <p>I'm trying to read a string which consists of a set of numbers followed by a string, wrapped with some other basic text.</p>
  
  <p>In other words, the format of the line is something like this:</p>
  
  <pre><code>Stuff&lt;5,10,-5,8,"Test string here."&gt;
  </code></pre>
  
  <p>Naively, I tried:</p>
  
  <pre><code>sscanf(str,"Stuff&lt;%d,%d,%d,%d,\"%s\"&gt;",&amp;i1,&amp;i2,&amp;i3,&amp;i4,str2);
  </code></pre>
  
  <p>But after some research I discovered <code>%s</code> is supposed to stop parsing when it gets to a whitespace character.  I found <a href="https://stackoverflow.com/questions/2854488/reading-a-string-with-spaces-with-sscanf">this question</a>, but none of the answers addresses the problem I have: the string could contain any character in it, including newline characters and properly escaped quotes.   The latter is not a problem, if I can just get sscanf to put everything after the first quote in the pre-allocated buffer I provide, I can strip the end off myself.  </p>
  
  <p>But how do I do this?  I can't use <code>%[]</code> because it requires something in it to terminate the string, and the only thing I want to terminate it is the null terminator.  So I thought, "Hey, I'll just use the null terminator!"  But <code>%[\0]</code> made the compiler grumpy:</p>
  
  <pre><code>warning: no closing ‘]’ for ‘%[’ format
  warning: embedded ‘\0’ in format
  warning: no closing ‘]’ for ‘%[’ format
  warning: embedded ‘\0’ in format
  </code></pre>
  
  <p>Using something like <code>%*c</code> won't work either, because I don't know exactly how many characters need to be taken.  I tried passing <code>strlen(str)</code> since it will be less than that, but <code>sscanf</code> returns 4 and nothing is put into <code>str2</code>, suggesting that perhaps because the length was too long it gave up and didn't bother.</p>
  
  <p>Update: I guess I could do something like:</p>
  
  <pre><code>sscanf(str,"Stuff&lt;%d,%d,%d,%d,\"%n",&amp;i1,&amp;i2,&amp;i3,&amp;i4,&amp;n);
  str2 = str+n;
  </code></pre>