title: Filtering out negative numbers using scanf
body: <p>my aim is to scan for some positive-only <code>a</code>, if negative number is entered, the function should print error:</p>
  
  <pre><code>if ( scanf("%u %lf", &amp;a, &amp;b) != 2 ) {
      //error
  }
  </code></pre>
  
  <p>Now the theory is that <code>scanf</code> returns successful writing attempts, so if I enter a negative number, <code>scanf</code> shouldn't return 2. My theory seems to be incorrect, why?</p>
  
  <p>Obviously I could simply <code>scanf</code> <code>%d</code> and then check whether <code>%d</code> is negative but right now I'm curious why my initial theory is incorrect. So is there a way without scanning and then comparing?</p>