title: Misbehavior of Scanf function in C
body: <p>Consider the following code:</p>
  
  
  
  <pre><code>#include&lt;stdio.h&gt;
  
  void main()
  {
      int p = 0;
      char a = 0;
      while(p == 0)
      {
          p = scanf("%[abc]c",&amp;a);
      }
      printf("%c",a);
  }
  </code></pre>
  
  <p>I know if you enter a character except <code>'a'</code>, <code>'b'</code>, or <code>'c'</code>, value of the getting character from input would not be set into the variable <code>a</code>. </p>
  
  <p>The <strong>problem</strong> is if you enter a value except the specified characters, the above loop never and never terminates. Apparently, after getting a not specified character in <code>scanf</code>, it will not get any character in the following loop iteration. <em>Where is the origin of this problem?</em></p>