Clearing the input buffer

This is a discussion on Clearing the input buffer within the C Programming forums, part of the General Programming Boards category; I read on the faqs that it is bad to use feof to control a loop. I've always used the ...

  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,220
    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, 01: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, 09:05 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21