Thread: how to know that the buffer is not clean??

  1. #1
    Banned
    Join Date
    Oct 2008
    Posts
    1,535

    how to know that the buffer is not clean??

    after i do scanf i want to check if the buffer is clean

    how to know that the buffer is not clean??

  2. #2
    spurious conceit MK27's Avatar
    Join Date
    Jul 2008
    Location
    segmentation fault
    Posts
    8,300
    Give it a sniff!

    Seriously, tho, you will be much happier with life if you write 'lil fgetc() or read() functions like me
    C programming resources:
    GNU C Function and Macro Index -- glibc reference manual
    The C Book -- nice online learner guide
    Current ISO draft standard
    CCAN -- new CPAN like open source library repository
    3 (different) GNU debugger tutorials: #1 -- #2 -- #3
    cpwiki -- our wiki on sourceforge

  3. #3
    Registered User
    Join Date
    Oct 2008
    Location
    TX
    Posts
    2,059
    Quote Originally Posted by transgalactic2 View Post
    after i do scanf i want to check if the buffer is clean

    how to know that the buffer is not clean??
    are you scanning the input into the buffer? not sure what you mean exactly by "after i do scanf i want to check if the buffer is clean..."

  4. #4
    Registered User
    Join Date
    Jan 2009
    Posts
    61
    dosent scanf by definition take all chars from input buffer and transfer to the buffer inside your program?

    hangon which buffer??? the terminal or your C buffer???

  5. #5
    Officially An Architect brewbuck's Avatar
    Join Date
    Mar 2007
    Location
    Portland, OR
    Posts
    7,396
    Quote Originally Posted by davo666 View Post
    dosent scanf by definition take all chars from input buffer and transfer to the buffer inside your program?
    No. It doesn't transfer anything, it converts the input characters according to the conversion specifiers. Characters which are converted are removed from the buffer. If a conversion fails, the characters which did not convert REMAIN in the buffer.

    And we are talking about the stdio buffer, not the terminal buffer.
    Code:
    //try
    //{
    	if (a) do { f( b); } while(1);
    	else   do { f(!b); } while(1);
    //}

  6. #6
    Hurry Slowly vart's Avatar
    Join Date
    Oct 2006
    Location
    Rishon LeZion, Israel
    Posts
    6,788
    use fgets/sscanf pair
    All problems in computer science can be solved by another level of indirection,
    except for the problem of too many layers of indirection.
    – David J. Wheeler

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 16
    Last Post: 10-29-2006, 05:04 AM
  2. writing a pack-style function, any advices?
    By isaac_s in forum C Programming
    Replies: 10
    Last Post: 07-08-2006, 08:09 PM
  3. buffer contents swapping
    By daluu in forum C++ Programming
    Replies: 7
    Last Post: 10-14-2004, 02:34 PM
  4. clean out a buffer
    By threahdead in forum C Programming
    Replies: 8
    Last Post: 02-23-2003, 01:04 PM
  5. Console Screen Buffer
    By GaPe in forum Windows Programming
    Replies: 0
    Last Post: 02-06-2003, 05:15 AM