title: C - Flush stdin input buffer without 'enter'
body: <p>I know there are a lot of questions about this, but i need a solution to flush the STDIN input buffer without pressing any key or 'enter'.</p>
  
  <p>I'm using <code>fgets(char, size, char)</code> (on a loop) to get an input stream from the keyboard and I want to press just 1 'enter' and go to the next input WITHOUT allocating the stdin buffer (if the buffer is bigger than the one specified on <em>fgets</em>, the first char array will be good but the next <em>fgets</em> on the loop will write the rest of the buffer on the next char array)</p>
  
  <p>Most of the solutions on SO are like this:</p>
  
  <pre><code>/** deletes the buffer on stdin */
  void flushStdin(){
      int c;
      while ((c = getchar()) != '\n' &amp;&amp; c != EOF);
  }
  </code></pre>
  
  <p>But this needs to press 'enter'. My whole code looks like this:</p>
  
  <pre><code>void readString(char *arrayString){
  
      fgets(arrayString, BUF_SIZE * sizeof(arrayString), stdin); //1st Enter here
      flushStdin(); //2nd Enter here
  
      //Deletes the newline '\n' at the end
      size_t len = strlen(arrayString);
      if (len &gt; 0 &amp;&amp; arrayString[len-1] == '\n')
          arrayString[--len] = '\0';
  
      return;
  }
  </code></pre>
  
  <p>Thank you!</p>