Mail Archives: djgpp/1995/02/27/10:01:28
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 <stdio.h>
#include <pc.h>
#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 <stdio.h>
#include <pc.h>
#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
- Raw text -