home *** CD-ROM | disk | FTP | other *** search
- Path: sparky!uunet!ogicse!uwm.edu!rpi!batcomputer!munnari.oz.au!goanna!ok
- From: ok@goanna.cs.rmit.oz.au (Richard A. O'Keefe)
- Newsgroups: comp.lang.c
- Subject: Re: strange things with gcc
- Message-ID: <15989@goanna.cs.rmit.oz.au>
- Date: 17 Nov 92 09:15:36 GMT
- Article-I.D.: goanna.15989
- References: <9232201.24197@mulga.cs.mu.OZ.AU> <9232210.1910@mulga.cs.mu.OZ.AU>
- Organization: Comp Sci, RMIT, Melbourne, Australia
- Lines: 36
-
- In article <9232210.1910@mulga.cs.mu.OZ.AU>, carl@montebello.ecom.unimelb.EDU.AU (Carl Brewer) writes:
- > wonder if anyone can offer a suggestion as to how to get this little
- > routine to work.
-
- Well, why don't you start by telling us what it is supposed to do?
-
- I see you are posting from Melbourne University. I know a lot of the
- people in the Computer Science department there, and they really are quite
- competent to help you with C/UNIX problems.
-
- > maybe there is some other way to clear the buffer from stdin (preferable
- > without using ioctl) ????
-
- There are TWO repeat TWO buffers involved.
- There is a stdio buffer which holds characters that your program has
- read from the operating system. Typically when reading from a terminal
- this is the rest of the current line. (And the UNIX mapping for '\n' is
- LINE FEED not CARRIAGE RETURN.) This is the buffer which fflush(stdin)
- flushes in the System V library (which is probably what acc uses).
-
- If all you want to do is discard the rest of the current line, the simple
- answer is to read whole lines in the first place, using fgets(). (I do
- hope you understand some of the reasons why scanf() is _not_ a good thing
- to use for reading from a terminal.)
-
- But there is ANOTHER buffer. UNIX lets you type ahead. There may be several
- lines that you have typed, which the operating system is hanging onto until
- your program asks for them. That buffer is part of the "terminal driver",
- and if you want to flush that one too you will _have_ to use ioctl. It is
- not at all hard to use. (It is conceivable that fflush(stdin) _might_ issue
- that ioctl() itself, but the "fflush" manual page for SunOS 4.1.2 certainly
- doesn't read that way.)
-
- I have written many many interactive programs under UNIX, and have never
- needed fflush(stdin). It really would help a lot if you told us what you
- are trying to accomplish.
-