flushing stdin

This is a discussion on flushing stdin within the C Programming forums, part of the General Programming Boards category; I prompt for input and the scanf function is skipped over because the stdin buffer contains data. How can I ...

  1. #1
    Registered User
    Join Date
    Apr 2006
    Posts
    31

    flushing stdin

    I prompt for input and the scanf function is skipped over because the stdin buffer contains data. How can I flush this beforehand? Everywhere I look tells me it's system dependent and I'm on linux and ncurses is recommended. There surely has to be a way in ansi c to do this.

  2. #2
    Code Goddess Prelude's Avatar
    Join Date
    Sep 2001
    Posts
    9,796
    This is a frequently asked question (hint hint).
    My best code is written with the delete key.

  3. #3
    Registered User 00Sven's Avatar
    Join Date
    Feb 2006
    Posts
    127
    LINKDon't double post.
    ~Sven
    Windows XP Home Edition - Dev-C++ 4.9.9.2
    Quote Originally Posted by "The C Programming Language" by Brian W. Kernignhan and Dennis M. Ritchie
    int fflush(FILE *stream)
    On an output stream, fflush causes any buffered but unwritten data to be written; On an input stream, the effect is undefined. It returns EOF for a write error, and zero otherwise. fflush(NULL) flushes all output streams.
    board.theprogrammingsite.com

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Flushing buffer
    By $l4xklynx in forum C Programming
    Replies: 6
    Last Post: 03-04-2009, 10:07 PM
  2. Another syntax error
    By caldeira in forum C Programming
    Replies: 31
    Last Post: 09-05-2008, 02:01 AM
  3. flushing stdin
    By crash88 in forum C Programming
    Replies: 2
    Last Post: 06-29-2006, 09:55 PM
  4. flushing stdin
    By crash88 in forum Linux Programming
    Replies: 1
    Last Post: 05-18-2006, 02:21 AM
  5. stdin question
    By oomen3 in forum C Programming
    Replies: 6
    Last Post: 02-19-2003, 02:52 PM

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