[comp.unix.admin] fflush doesn't work on SunOS 4.1 ?

pren@bbn.com (Peifong Ren) (05/17/91)

Can someone help me with this problem?


In going from Sun OS 3.5 to 4.1, it seems that fflush(stdin) no longer
clears the keyboard input buffer.  Is this true, and how should I clear
keyboard input under 4.1?

In the example program below, when compiled under 4.1, the <return> from
the user's first typein remains in the buffer after the scanf and
fflush,
so it is seen by the getc, and the the user never has a chance to supply
the second typein.

Please send reply to pren@bbn.com!
Thanks!

=================
#include <stdio.h>
int i;
main() {
  printf("type a number and <return>: ");
  fflush(stdout);
  scanf("%d", &i);
  fflush(stdin); /* flush any arg terminator char */
  printf(" type a single char and <return>: ");
  fflush(stdout);
  i = getc(stdin);
  printf(" char=%d\n", i);
  fflush(stdout);
}
===================