Thread: a way to check if anything is in the buffer...

  1. #1
    Registered User
    Join Date
    Dec 2005
    Posts
    119

    a way to check if anything is in the buffer...

    I was wondering if there's a way to see if there is anything in the buffer or not. The reason I ask is that I've noticed that if you have a line in your program to clear the buffer, and the user typed more than the string could hold, so that it is actually neccessary to clear the buffer, then it works great. But if your user doesn't overflow the string, then you try to clear the buffer, the user will have to hit ENTER to get past it, and I'm trying to fix this. Thanks

  2. #2
    Gawking at stupidity
    Join Date
    Jul 2004
    Location
    Oregon, USA
    Posts
    3,218
    There is no standard way to do what you're asking.

    This is why most experienced programmers avoid the use of scanf(). To get around the problem you can fgets() the input and then use sscanf() on the buffer that fgets() fills in for you.
    If you understand what you're doing, you're not learning anything.

  3. #3
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,661
    Exactly, you always know what the stream state is when using fgets(). If newlines are really that important to you, it's easy (say strchr) to search the buffer for a newline, and take whatever action you see fit depending on whether you find one or not.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. BN_CLICKED, change button style
    By bennyandthejets in forum Windows Programming
    Replies: 13
    Last Post: 07-05-2010, 11:42 PM
  2. Question about Multiple threads and ring buffer.
    By qingxing2005 in forum C Programming
    Replies: 2
    Last Post: 01-15-2007, 12:30 AM
  3. Replies: 4
    Last Post: 09-23-2005, 10:51 AM
  4. Console Screen Buffer
    By GaPe in forum Windows Programming
    Replies: 0
    Last Post: 02-06-2003, 05:15 AM
  5. getline problem
    By Unregistered in forum C++ Programming
    Replies: 4
    Last Post: 10-06-2001, 09:28 AM