Date: Mon, 27 Feb 1995 09:04:36 -0500 From: kagel AT quasar DOT bloomberg DOT com To: jkeene AT unlinfo DOT unl DOT edu Cc: djgpp AT sun DOT soe DOT clarkson DOT edu Subject: Re: Question reagarding kbhit() Reply-To: kagel AT ts1 DOT bloomberg DOT com Errors-To: postmaster AT ts1 From: jkeene AT unlinfo DOT unl DOT edu (Jon Keene) Date: Mon, 27 Feb 1995 00:33:38 -0600 (CST) X-Mailer: ELM [version 2.4 PL20] Content-Type: text Content-Length: 581 Could anyone tell me why it is that when I run the following program, it pauses for the keyboard hit _before_ doing any output? Ponderously yours, Rumball --- #include #include #define BUFSIZE 1840 /* (80 * 23) */ #define BLANK ' ' main () { int i; int buf[BUFSIZE]; for ( i = 0; i < BUFSIZE; i++ ) buf[i] = BLANK; buf[0] = 'a'; buf[BUFSIZE - 1] = 'z'; for ( i = 0; i < BUFSIZE; i++ ) printf("%c", buf[i]); while (!kbhit()) ; return 0; } -- The output function, printf(), writes to stdout which is a buffered file. You either must write to stderr, using fprintf( stderr, ... ), or call fflush( stdout ) before calling kbhit(). Thus: #include #include #define BUFSIZE 1840 /* (80 * 23) */ #define BLANK ' ' main () { int i; int buf[BUFSIZE]; for ( i = 0; i < BUFSIZE; i++ ) buf[i] = BLANK; buf[0] = 'a'; buf[BUFSIZE - 1] = 'z'; for ( i = 0; i < BUFSIZE; i++ ) printf("%c", buf[i]); fflush( stdout ); while (!kbhit()) ; return 0; } -- Art S. Kagel, kagel AT ts1 DOT bloomberg DOT com