title: What does fflush(stdin) do in C programing?
body: <p>I am very new to C programming and I am trying to understand how <code>fflush(stdin)</code> really works.</p>
  
  <p>In the following example does <code>fflush(stdin)</code> clears all the buffer or it clears whatever entered after the third item? What I mean is user enters account number, space, name, space, balance. Is that true that from this point on, whatever the user enters will be flushed with <code>fflush(stdin)</code>?  and <code>stdin</code> won't be empty. </p>
  
  <p>Why do I say that is because it enters into a while loop and starts writing to the text file.</p>
  
  <p>My second question is whether <code>Ctrl-Z</code> will tell the OS to stop asking the user for entering input?</p>
  
  <pre><code>printf( "Enter the account name and balance. (separated by spaces)\n" );
    printf( "Enter EOF to end input. (Ctrl-Z)\n" );
    printf( "? " );
    scanf( "%d%s%lf", &amp;account, name, &amp;balance );
    fflush(stdin);
  
    // write account, name and balance into file with fprintf
    while ( !feof( stdin ) )
    { 
       //fflush(stdin);
       fprintf( cfPtr, "%d %s %.2f\n", account, name, balance );
       printf( "? " );
       scanf( "%d%s%lf", &amp;account, name, &amp;balance );
    }
  
    fclose( cfPtr );
  </code></pre>