Thread: clearing input buffert.

  1. #1
    Wannabe Coding God
    Join Date
    Mar 2003
    Posts
    259

    clearing input buffert.

    I need to clear the input buffert (stdin) so that when I call fgets I only get the most resent input in it. So far I've figured that I should do it after I get the input from it but I don't know how to do it in the firsty place since I shouldn't use fflush (stdin). And don't want to use the one on the faq pages since it requiers somthing to be inputed if there ins't anything in it.
    Last edited by Shogun; 06-06-2003 at 12:49 PM.
    They say that if you play a Windows Install CD backwords, you hear satanic messages. That's nothing; play it forward and it installs Windows.

  2. #2
    Registered User
    Join Date
    May 2003
    Posts
    148
    flush input

    Code:
    #include <stdio.h>
    
    void eatToNL(FILE * inputStream)
    {
        int c;
        /* Eat till (& including) the next newline */
        while ((c = getc(inputStream)) != EOF)
           if (c == '\n')
               break;
    }
    
    /* blah blah */
    eatToNL(stdin);
    /* blah blah */

  3. #3
    Been here, done that.
    Join Date
    May 2003
    Posts
    1,164
    That will only work if there is data in the buffer. If there isn't, you hang until someone hits a key.
    And don't want to use the one on the faq pages since it requiers somthing to be inputed if there ins't anything in it.
    What compiler are you using?
    Definition: Politics -- Latin, from
    poly meaning many and
    tics meaning blood sucking parasites
    -- Tom Smothers

  4. #4
    Wannabe Coding God
    Join Date
    Mar 2003
    Posts
    259
    GCC 1 ;(
    They say that if you play a Windows Install CD backwords, you hear satanic messages. That's nothing; play it forward and it installs Windows.

  5. #5
    Wannabe Coding God
    Join Date
    Mar 2003
    Posts
    259
    okey.... and what do you mean by "broken by design"?

    thx a ton for the help.
    They say that if you play a Windows Install CD backwords, you hear satanic messages. That's nothing; play it forward and it installs Windows.

  6. #6
    Wannabe Coding God
    Join Date
    Mar 2003
    Posts
    259
    I am using fgets but the thing is if the user prints like 100 Ps then my buffert wont catch all of it and then I should trow the left overs away since I know I won't need the left overs witch it doesn't take.
    Last edited by Shogun; 06-07-2003 at 01:37 PM.
    They say that if you play a Windows Install CD backwords, you hear satanic messages. That's nothing; play it forward and it installs Windows.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. About aes
    By gumit in forum C Programming
    Replies: 13
    Last Post: 10-24-2006, 03:42 PM
  2. Structure and Linked List User Input Question
    By kevndale79 in forum C Programming
    Replies: 16
    Last Post: 10-05-2006, 11:09 AM
  3. Custom Made Safe Input Function
    By Beast() in forum C Programming
    Replies: 6
    Last Post: 08-21-2004, 10:19 PM
  4. text input buffer clearing
    By red_Marvin in forum C++ Programming
    Replies: 4
    Last Post: 03-20-2003, 03:17 PM
  5. need help with some input
    By blindleaf in forum C Programming
    Replies: 2
    Last Post: 03-16-2003, 01:50 PM