Thread: About Flush the input buffer

  1. #1
    Registered User
    Join Date
    Dec 2010
    Posts
    61

    About Flush the input buffer

    Greetings EveryOne

    About Flush the input buffer in FAQ:

    Code:
    #include <stdio.h> 
    
    int main(void)
    {
      int   ch;
      char  buf[BUFSIZ];
      
      puts("Flushing input");
      
      while ((ch = getchar()) != '\n' && ch != EOF);
      
      printf ("Enter some text: ");
      
      if (fgets(buf, sizeof(buf), stdin))
      {
        printf ("You entered: %s", buf);
      }
      
      return 0;
    }
    is this where the input buffer get cleared?

    Code:
    while ((ch = getchar()) != '\n' && ch != EOF);
    Thank You In Advance

  2. #2
    Banned
    Join Date
    Aug 2010
    Location
    Ontario Canada
    Posts
    9,547
    Yes... that is what it says.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Help with input flush
    By KarrieWojo in forum C Programming
    Replies: 12
    Last Post: 12-29-2007, 02:38 AM
  2. Flush Input Buffer
    By zx-1 in forum C Programming
    Replies: 41
    Last Post: 10-29-2005, 08:58 AM
  3. easier way to flush input?
    By GSG-9 in forum C Programming
    Replies: 2
    Last Post: 02-05-2005, 02:52 PM
  4. How to Flush standard input?
    By Hardboy in forum C++ Programming
    Replies: 7
    Last Post: 02-21-2003, 03:30 PM
  5. How to flush the buffer
    By Unregistered in forum C Programming
    Replies: 6
    Last Post: 07-26-2002, 03:28 AM