Posts: 3,616
Threads: 287
Joined: Jan 2003
I think I get it.
Okay, next question - is there a function that is the equivalent of INKEY$?
f only life let you press CTRL-Z.
--------------------------------------
Freebasic is like QB, except it doesn't suck.
Posts: 6,419
Threads: 74
Joined: Mar 2002
Not exactly, but you can do some workarounds with this:
Code:
#include <conio.h>
#include <stdio.h>
int main(void)
{
char c;
printf("Press 's' to exit \n");
do
{
/* If there is a character in the keyboard buffer... */
if (kbhit())
{
c = getch(); /* get it */
}
} while (c!='s');
}
The above code works in Borland C, and I am not sure about it is portable or not (try it in your compiler, it may work). That "kbhit" stuff sounds quite nasty, so...
...for real usability and portability, you better learn to work with a keyboard handler, for example allegro's
Allegro's work like this:
Code:
#include <allegro.h>
#include <stdio.h>
int main(void)
{
allegro_init();
install_keyboard(); /* Installs the keyboard handler */
printf("Press s to exit\n");
while(!key[KEY_S]);
remove_keyboard();
allegro_exit();
}
Posts: 3,616
Threads: 287
Joined: Jan 2003
Erm...don't you need END_OF_MAIN() at the end of an allegro app?
Also, I'm using mingw32...so no conio.h for me.
f only life let you press CTRL-Z.
--------------------------------------
Freebasic is like QB, except it doesn't suck.
Posts: 6,419
Threads: 74
Joined: Mar 2002
Yeah, you need that END_OF_MAIN; I was testing my code in DJGPP (like your compiler but for MSDOS) and you don't need it
Anyways, I don't know another replacement. Use Allegro's
Posts: 3,616
Threads: 287
Joined: Jan 2003
Btw, what's with that WHILE statement? No following statement or code block...huh?
f only life let you press CTRL-Z.
--------------------------------------
Freebasic is like QB, except it doesn't suck.
Posts: 6,419
Threads: 74
Joined: Mar 2002
Look at this:
The while statement is
Code:
while (<condition>)
instruction;
Instruction can be a single instruction:
Code:
while(!key[KEY_S])
rectfill(screen, 0, 0, SCREEN_H, SCREEN_W, makecol(rand()&255,rand()&255,rand()&255));
or an instruction block:
Code:
while(!key[KEY_S])
{
// Stuff here
}
I just used the simplest instruction: ";" which does nothing:
Code:
while(!key[KEY_S])
;
Note that while(<condition>) is not followed by a colon but by an instruction. My instruction is null, so the following colon is the separator after a null instruction. I am used to write it in a single line:
that while just waits until 's' is pressed, does nothing in the meantime, just wait. In QB:
Code:
WHILE (NOT key(KEY_S)):WEND
What I like most about C is the flexibility in its syntax.
Posts: 3,616
Threads: 287
Joined: Jan 2003
Ah! I see. What I like about C, also, is that you can do a lot on one line. :wink:
f only life let you press CTRL-Z.
--------------------------------------
Freebasic is like QB, except it doesn't suck.