Thread: Clearing the input buffer

  1. #1
    Registered User
    Join Date
    Jan 2005
    Posts
    204

    Clearing the input buffer

    I read on the faqs that it is bad to use feof to control a loop. I've always used the following loop to clear the input buffer and now I am wondering how could I change it to make it correct. Thanks.
    Code:
    while(!feof(stdin) && getchar() != '\n');

  2. #2
    Registered User
    Join Date
    Jan 2002
    Location
    Vancouver
    Posts
    2,212
    while ((ch = getchar()) != '\n' && ch != EOF);

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Checking array for string
    By Ayreon in forum C Programming
    Replies: 87
    Last Post: 03-09-2009, 03:25 PM
  2. can someone help me with these errors please code included
    By geekrockergal in forum C Programming
    Replies: 7
    Last Post: 02-10-2009, 02:20 PM
  3. Clearing the input stream
    By abh!shek in forum C Programming
    Replies: 10
    Last Post: 05-18-2008, 03:50 PM
  4. How to put a Char into the Input buffer of a console?
    By Aidman in forum C++ Programming
    Replies: 10
    Last Post: 03-09-2003, 10:05 AM