[Coco] [Color Computer] Update: Inkey for Microware C...
Mannequin*
mannequin at primary.net
Mon Dec 8 22:52:00 EST 2003
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?
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/
More information about the Coco
mailing list