title: use getchar to discard all but first character using loop c code
body: <p>I would like to find out, how to improve this function to control input and display of input for only using first character from getchar function
  avoiding the rest that user might type. When the user types several characters printf prints that many times. How to correct that flaw?</p>
  
  <pre><code>    int checkLevelValidity(int levelOne, int levelTwo) {
          int level = 0;  //initialize to value zero (false)
          printf("Choose difficulty level: press (1) for single digit 
              or (2) for double: ");
  
          //get user input when level value is zero at start
          while ( level == 0 ) {       
  
              scanf("%d", &amp;level);
              //if input is not an integer (false on return from scanf)
              if ( level == 0 ) {     
  
                  printf("Enter (%d or %d): ", levelOne, levelTwo);
  
                  getchar();
              }
              //if input is integer then check for correct level value
              //if input less than (1) or larger than (2)
              if ( ( level != 0 ) &amp;&amp; 
                  ( level &lt; levelOne || level &gt; levelTwo ) ) {
  
                  printf("Enter correct level (%d or %d): ", 
                      levelOne, levelTwo);
  
                  //reassign zero value to loop again 
                  level = 0;
              }
          }
          return level;       //returns correct value of (1) or (2)
      }
  </code></pre>