title: while loop strange behaviour in C
body: <p>I am experiencing a strange behaviour of while loop in the following program.</p>
  
  <pre><code>#include &lt;stdio.h&gt;
  
  int main ()
  {
  
      char confirm;
  
      printf("Do you want to proceed? (Y/N):\n");
      scanf(" %c", &amp;confirm);
      while (confirm != 'Y' &amp;&amp; confirm != 'y' &amp;&amp; confirm != 'N' &amp;&amp; confirm != 'n')
      {
           printf("Please enter a valid answer (Y/N):\n");
           scanf(" %c", &amp;confirm);
      }
   return 0;
  }
  </code></pre>
  
  <p>Basically, I want the program only to accept 'Y', 'N', 'y' or 'n' characters. The above code works but when I enter a string as input, 
  it prints "Please enter a valid answer (Y/N):" as many times as the characters of the string. Something like below:</p>
  
  <pre><code>Do you want to proceed? (Y/N):
  a
  Please enter a valid answer (Y/N):
  adsfaf
  Please enter a valid answer (Y/N):
  Please enter a valid answer (Y/N):
  Please enter a valid answer (Y/N):
  Please enter a valid answer (Y/N):
  Please enter a valid answer (Y/N):
  Please enter a valid answer (Y/N):
  </code></pre>
  
  <p>How can I get rid of this. Can somebody help?</p>