title: How to validate input using scanf
body: <p>How can I validate the user input by using scanf. Right now I have something like this, but doesn't work.</p>
  
  <p>NOTE: I have the atoi just to validate that the scanf validation works.</p>
  
  <pre><code>scanf("%[0987654321.-]s",buf);
  
  i = atoi(buf);
  
  if(i)
      index = i;
  </code></pre>