title: Using sscanf for an unknown number of variables
body: <p>For a school assignment, I have to read in a string that has at least one but up to three variables(named command, one, and two). There is always a character at the beginning of the string, but it may or may not be followed by integers. The format could be like any of the following:</p>
  
  
  
  <pre class="lang-none prettyprint-override"><code>i 5 17 
  i 3
  p
  d 4
  </code></pre>
  
  <p>I am using fgets to read the string from the file, but I'm having trouble processing it. I've been trying to use sscanf, but I'm getting segfaults reading in a string that only has one or two variables instead of three. </p>
  
  <ul>
  <li>Is there a different function I should be using? </li>
  <li>Or is there a way to format sscanf to do what I need? </li>
  </ul>
  
  <p>I've tried <code>sscanf(buffer, "%c %d %d", command, one, two)</code> and several variations with no luck.</p>