Thread: rewind(stdin); ? Right or Wrong?

  1. #1
    C/C++Newbie Antigloss's Avatar
    Join Date
    May 2005
    Posts
    216

    rewind(stdin); ? Right or Wrong?

    As fflush(stdin); is wrong. Some one suggests using rewind(stdin) to eliminate input buffer and also clear error state of the stream. Is that right?

    I used Dev-C++ to compile this code, and it really works. Is it right to use rewind(stdin); ?

    As for as I know, rewind(fp) is equivalent to fseek(fp, 0L, SEEK_SET); clearerr(fp). So I guess this is another wrong thing to clear input buffer.
    Last edited by Antigloss; 10-26-2006 at 07:56 AM.

  2. #2
    Registered User SKeane's Avatar
    Join Date
    Sep 2006
    Location
    England
    Posts
    234
    It's recommended by Microsoft

    http://support.microsoft.com/default...kb;en-us;41159

    So I'm tempted to say it's probably the wrong thing to do

    <edit>
    Of course if stdin isn't a keyboard, you'd get "interesting" results.
    </edit>

  3. #3
    Cat without Hat CornedBee's Avatar
    Join Date
    Apr 2003
    Posts
    8,895
    You can't seek on console streams, so I dare say it's a wrong thing to do, unless stdin has been redirected to a file. There is no ISO C way of finding out whether this has happened, though I believe there's a POSIX way.
    All the buzzt!
    CornedBee

    "There is not now, nor has there ever been, nor will there ever be, any programming language in which it is the least bit difficult to write bad code."
    - Flon's Law

  4. #4
    Code Goddess Prelude's Avatar
    Join Date
    Sep 2001
    Posts
    9,897
    >Some one suggests using rewind(stdin) to eliminate input buffer and also clear error state of the stream. Is that right?
    Hell no.

    >Is it right to use rewind(stdin); ?
    Calling rewind on stdin is perfectly legal. The behavior is erratic though, so it's not recommended in the general case.
    My best code is written with the delete key.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 9
    Last Post: 07-15-2004, 03:30 PM
  2. Debugging-Looking in the wrong places
    By JaWiB in forum A Brief History of Cprogramming.com
    Replies: 1
    Last Post: 11-03-2003, 10:50 PM
  3. Confused: What is wrong with void??
    By Machewy in forum C++ Programming
    Replies: 19
    Last Post: 04-15-2003, 12:40 PM
  4. God
    By datainjector in forum A Brief History of Cprogramming.com
    Replies: 746
    Last Post: 12-22-2002, 12:01 PM
  5. Whats wrong?
    By Unregistered in forum C Programming
    Replies: 6
    Last Post: 07-14-2002, 01:04 PM