title: Determine if a C string is a valid int in C
body: <p>I need to check if a  C string is a valid integer.</p>
  
  <p>I tried both</p>
  
  <pre><code>int num=atoi(str);
  </code></pre>
  
  <p>and </p>
  
  <pre><code>int res=sscanf(str, "%d", &amp;num);
  </code></pre>
  
  <p>But sending the string <code>"8 -9  10"</code> in both of the lines returned simply 8, without indicating the invalidity of this string.</p>
  
  <p>Can anyone suggest an alternative?</p>