www.delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/1995/02/27/12:10:32

To: djgpp AT sun DOT soe DOT clarkson DOT edu
Path: mantis!not-for-mail
From: olly AT mantis DOT co DOT uk (Olly Betts)
Newsgroups: mail.djgpp
Subject: Re: Question reagarding kbhit()
Date: 27 Feb 1995 16:32:53 -0000
Organization: Mantis Consultants Ltd, Cambridge, UK
Lines: 35
References: <9502270633 DOT AA23500 AT unlinfo DOT unl DOT edu>

In article <9502270633 DOT AA23500 AT unlinfo DOT unl DOT edu>,
Jon Keene <jkeene AT unlinfo DOT unl DOT edu> wrote:
>
>Could anyone tell me why it is that when I run the following
>program, it pauses for the keyboard hit _before_ doing any output?

Buffering.

>#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); /* ensure buffers are written out */

>        while (!kbhit()) 
>                ;
>        return 0;
>}

Olly
-- 
Putting the "Ol" in technology.

- Raw text -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019