home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #27 / NN_1992_27.iso / spool / comp / lang / c / 16650 < prev    next >
Encoding:
Internet Message Format  |  1992-11-17  |  2.2 KB

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