Skip site navigation (1)Skip section navigation (2)
Date:      Fri, 14 Jun 1996 00:35:28 -0600 (MDT)
From:      wes@intele.net
To:        jsigmon@www.hsc.wvu.edu
Cc:        chat@freebsd.org
Subject:   Re: Any alternatives for kbhit() and getch
Message-ID:  <199606140635.AAA00433@obie.softweyr.com>
In-Reply-To: <199606132128.XAA15302@uriah.heep.sax.de>
References:  <31BF97BC.5E2D@access.mountain.net> <199606132128.XAA15302@uriah.heep.sax.de>

next in thread | previous in thread | raw e-mail | index | archive | help
Jeremy Sigmon asked:
 % I am writing a timed program.  I need to be checking the
 % time while waiting for input.  This is to be written as much as
 % possible in ANSI C.

Joerg Wunsch cleverly replied:
 > It's impossible in ANSI C (kbhit() ain't ANSI either).
 > 
 > For the Unix environment, use select(2).  It also handles the timing
 > for you.  You might need to turn the terminal into ``raw'' mode as
 > well, otherwise all input processing will be handled in terms of lines.
 > RTFM termios(7) for this.

You will most certainly need to put the terminal into raw mode; see
cfmakeraw(3) while you're spelunking in the man pages.  If you want
to do reads that may be "timed out", select(2) is ideal.  If you want
to time the execution of your program, you may use the time(1) command,
or simply call gettimeofday at the beginning and end of your program
and print the difference.

-- 
   Wes Peters	| Yes I am a pirate, two hundred years too late
    Softweyr 	| The cannons don't thunder, there's nothing to plunder
   Consulting	| I'm an over forty victim of fate...
 softweyr@xmission.com	|				Jimmy Buffett



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?199606140635.AAA00433>