02-03-2004, 01:32 AM
Pages: 1 2
02-03-2004, 01:41 AM
Not exactly, but you can do some workarounds with this:
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 <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();
}
02-03-2004, 01:47 AM
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.
Also, I'm using mingw32...so no conio.h for me.
02-03-2004, 02:49 AM
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
Anyways, I don't know another replacement. Use Allegro's
02-03-2004, 02:55 AM
Btw, what's with that WHILE statement? No following statement or code block...huh?
02-03-2004, 04:21 AM
Look at this:
The while statement is
Instruction can be a single instruction:
or an instruction block:
I just used the simplest instruction: ";" which does nothing:
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:
What I like most about C is the flexibility in its syntax.
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:
Code:
while(!key[KEY_S]);
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.
02-03-2004, 05:48 AM
Ah! I see. What I like about C, also, is that you can do a lot on one line. :wink:
Pages: 1 2