Mail Archives: djgpp/1995/02/27/03:40:08
jkeene AT unlinfo DOT unl DOT edu (Jon Keene) wrote (Subject: Question regarding
kbhit()):-
> Could anyone tell me why it is that when I run the following program, it
> pauses for the keyboard hit _before_ doing any output?
#include <stdio.h>
#include <pc.h>
#define BUFSIZE 1840 /* (80 * 23) */
#define BLANK ' '
main () {int i, 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;}
printf() (formatted print to screen) stores the output characters in a buffer
and only sends the bufferful to the screen when it is told to print a '\n'.
`fflush(stdout);' called after each fprint() call will empty FILE* stdout's
buffer and thus cause the behavior that you seem to want.
- Raw text -