[Coco] [Color Computer] Update: Inkey for Microware C...
Gene Heskett
gene.heskett at verizon.net
Tue Dec 9 00:58:00 EST 2003
On Monday 08 December 2003 22:50, Mannequin* wrote:
>Here is the code that Mike sent:
>
>char inkey() {
> char ch;
>
> fflush(stdout); /* needed if you're using bufrered I/O anywhere
> in the prog */
> if( getstat(1, 0)) /* 2nd arg must be the I/O
> channel (0==stdin) */
> return(0);
> read(0, 1, &ch); /* caution-- check argument order here */
> return(ch);
>}
>
>I did see one thing that Mike pointed out in his comments. He needed
> to rearrange the arguments in the read function:
>
>read (0, &ch, 1);
>
>Anyway, I've implemented that code in to a small test file:
>
>/* myconio.c: Test of inkey () function. */
>
>#include <stdio.h> /* For fflush () and other I/O functions.*/
>#include <sgstat.h> /* For the getstat () function. */
>
>int inkey (void) /* Yeah, I changed it from a char to int
> return. */ {
> char ch;
>
> fflush (stdout);
> if (getstat (1, 0))
> return 0;
> read (0, &ch, 1);
> return ch;
>}
>
>int main (void)
>{
> char ch = '\0';
>
> while ((ch = inkey ()) != 35) /* 35 = '#'; My fake-EOF
> character. */ {
> if (ch != 0) /* Or
> NULL */ printf ("ch = %c = %i\n", ch, ch);
> }
>
> return 0;
>}
>
>So, when I compile and run this, it always prints the character I
> typed in before it hits the printf () function. Here's an example:
>
>OS9: myconio
>fch = f = 102
>#
>OS9:
>
>So how do I go about defeating this?
I believe you'll need to setup a setstt call to shut off the console
echoing, or do the equ in your program of calling 'tmode -echo'
before the fflush, and another to 'tmode echo' immediately after the
printf statement do when its done you have a cli that echos what you
type again. Don't carve that in stone though, its been a while since
I've coded in C. I *think* thats "system 'tmode -echo'" without the
dbl quotes IIRC, somebody rescue me here, puleaze! I know it can be
done, I've done it, but that was years back up the log.
>Thanks in advance!
>- Mannequin*
>
>------------------------ Yahoo! Groups Sponsor
> ---------------------~--> Buy Ink Cartridges or Refill Kits for
> your HP, Epson, Canon or Lexmark Printer at MyInks.com. Free s/h on
> orders $50 or more to the US & Canada.
> http://www.c1tracking.com/l.asp?cid=5511
>http://us.click.yahoo.com/mOAaAA/3exGAA/qnsNAA/CFFolB/TM
>--------------------------------------------------------------------
>-~->
>
>Brought to you by the 6809, the 6803 and their cousins!
>
>Your use of Yahoo! Groups is subject to
> http://docs.yahoo.com/info/terms/
--
Cheers, Gene
AMD K6-III at 500mhz 320M
Athlon1600XP at 1400mhz 512M
99.22% setiathome rank, not too shabby for a WV hillbilly
Yahoo.com attornies please note, additions to this message
by Gene Heskett are:
Copyright 2003 by Maurice Eugene Heskett, all rights reserved.
More information about the Coco
mailing list