Re: (C) missing semi-colon

From: Arthur J. O'Dwyer (ajo_at_nospam.andrew.cmu.edu)
Date: 11/06/04

  • Next message: Mark P: "Re: redefining operator new and STL classes"
    Date: Sat, 6 Nov 2004 15:25:38 -0500 (EST)
    
    

    On Thu, 4 Nov 2004, Paul Fedorenko wrote:
    >
    > You mentioned no less than three times that fflush() is undefined for input
    > streams, and that I "must extract the characters with an input function" if
    > I want to make sure nothing's left over in stdin from previous inputs.
    > That's exactly what I'm trying to do, but know no other way of going about
    > it. So if you have a more acceptable solution, I'd be more than happy to
    > find out about it and start using it.

       Alwyn, Herbert, and Mike have all given you the same answer, but I
    haven't seen anybody explicitly point out that that snippet won't actually
    prevent type-ahead or flush any buffers --- it will just discard some
    characters from the input buffer.
       Normally, C streams behave this way:

         Enter a number: <user enters "42 43 44\nfoo\n">
         <read "42">
         Enter a string: <read "43 44">

       The given snippets act this way:

         Enter a number: <user enters "42 43 44\nfoo\n">
         <read "42", discard up to newline>
         Enter a string: <read "foo", discard newline>

    But to avoid "type-ahead," we'd really want this behavior:

         Enter a number: <user enters "42 43 44\nfoo\n">
         <read "42", flush input buffer>
         Enter a string: <user enters some new input>

    That's something standard C doesn't give us. But there are certainly
    platform-specific libraries that can give you this behavior; ask in
    a group dedicated to your platform.

    -Arthur


  • Next message: Mark P: "Re: redefining operator new and STL classes"