Re: [cc65] cc65 and BASIC GET?

From: Groepaz <groepaz1gmx.net>
Date: 2005-09-26 23:31:19
On Monday 26 September 2005 23:21, Raj Wurttemberg wrote:
> I'm making a simple menu in my program to get a single key and I would like
> to make sure I am using C properly to emulate the BASIC GET statement.
>
> [Note: I'm learning C as I write this program]
>
> I read about the "getchar()" statement (macro?) and saw that it wasn't ANSI
> C so I was not surprised to see that it was not in cc65 and I don't know
> enough about macros yet. Going through the sample programs included with
> cc65 I found "cgetc (void)" used in hello.c to get a key. It works, but is
> this the proper way to use it?
>
> 	unsigned char menusel;
> 	fflush (stdout);
> 	menusel = cgetc();
>
> 	// Debug output
> 	printf("key pressed: %c", menusel);

you probably want something like this

	cprintf("press a key:");
	cursor(1);	// enable the cursor
	while(!kbhit())
	{
		// do something until key pressed
	}
	c=cgetc(); // get the key
	
you should not mix regular standard i/o (which stdout and printf belongs to) 
and the conio library, since that will lead to all sorts of "interisting" 
results :=P

-- 

http://www.hitmen-console.org
http://www.gc-linux.org/docs/yagcd.html
http://www.pokefinder.org
http://ftp.pokefinder.org

The question of whether a computer can think is no more interesting than the 
question of whether a submarine can swim. 
<Edsgar W. Dijkstra>

----------------------------------------------------------------------
To unsubscribe from the list send mail to majordomo@musoftware.de with
the string "unsubscribe cc65" in the body(!) of the mail.
Received on Mon Sep 26 23:31:30 2005

This archive was generated by hypermail 2.1.8 : 2005-09-26 23:31:33 CEST