title: checking the input type in C
body: <p>I want to check if my input is an integer (and not a char or string for example).
  I stumbled across this code (that works):</p>
  
  <pre><code>#include &lt;stdio.h&gt;
  
  int main (void)
  {
      float a;
      int q;
  
      printf("\nInsert number\t");
      scanf("%f",&amp;a);
  
      q=(int)a;
      ++q;
  
      if((q - a) != 1)
          printf("\nThe number is not an integer\n\n");
      else
          printf("\nThe number is an integer\n\n");
  
      return 0;
  }
  </code></pre>
  
  <p>Can someone please explain why it works?</p>