does anyone know code that would grab input from the user but not if there is none entered... unlike the "cin>>" where it will wait for input and the enter key to be pushed.
does anyone know code that would grab input from the user but not if there is none entered... unlike the "cin>>" where it will wait for input and the enter key to be pushed.
Well you could read the FAQ
If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
If at first you don't succeed, try writing your phone number on the exam paper.
i dont think that you understood my question but that answer might work ... thx. Is there way to grab words like that without using a while loop with the suggested code from the faq.
> Is there way to grab words
Yeah, you separate the "get some characters" from the "split out the words" functions.
If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
If at first you don't succeed, try writing your phone number on the exam paper.
Actually this raises an interesting ?. So far my belief is that "requests for input" normally halts until one is provided. Is there a way to return after a certain period of time after waiting for input such as burying the code itself within a time controlled loop of some sort? (Believe me I'm thinking this one through.. so no sarcastic comments please )
Is there a problem with the FAQ all of a sudden, or do you just timeout reading it?
> So far my belief is that "requests for input" normally halts until one is provided
Normally yes, but it is controllable depending on your OS
So go read the FAQ again
> such as burying the code itself within a time controlled loop of some sort?
Sure there is, if that is what you want to do
What is so difficult about this?
If you want to replace check_for_key_press() with check_for_key_press_with_timeout() then that's up to you.Code:int main ( ) { while ( !dead ) { if ( check_for_key_press() ) { ch = get_key_press(); move_player(player,ch); } move_enemies(enemies); dead = do_combat(player,enemies); if ( !dead ) { redraw(player,enemies); } else { printf( "Game over\n" ); } } return 0; }
It would probably look something like this
Code:int check_for_key_press_with_timeout( int limit ) { int result = 0; for ( i = 0 ; i < limit && !result ; i++ ) { result = check_for_key_press(); sleep( 1 ); } return result; }
If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
If at first you don't succeed, try writing your phone number on the exam paper.
is the timeout outlined in the faq could you send me a link cause i cant seem to find it and salem i thank you for your patience with me.
Style is overrated.
- —₽‚¢‰Î -
> is the timeout outlined in the faq
No.
Like all FAQs, it does not explain how to do everything. It tells you about common things (F does mean frequently after all), and points the way to help you figure out where to look next.
If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
If at first you don't succeed, try writing your phone number on the exam paper.
your getkey press doesn't wait for the user to push enter but it does wait for a key press i'm looking for a function that will move on if there hasn't ever been a key pressed and not wait for one.
Style is overrated.
- —₽‚¢‰Î -
You want to poll for a keypress event. The code to do this is wildly different on different systems. For example, under MSDOS you might call the BIOS to do it for you in a compiler specific way.
On Unix, some variation of an ioctl will do what you want:Code:_AX = 0x00; geninterrupt(0x16);
Some compilers support a function that performs this specific task, such as kbhit on many Windows compilers. Such a function would return true if characters are waiting to be extracted from the buffer and false otherwise.Code:int n; ioctl(0, FIONREAD, &n);
edward how do you call the kbhit function in a windows compiler...i have visual c++ 6.0... and what include file do i have to use for that... is it in the standard iostream.... ?
Style is overrated.
- —₽‚¢‰Î -
Check the extensive online help that comes with VC++ 6.0. It will answer this and many other basic questions.Originally posted by Ajsan
edward how do you call the kbhit function in a windows compiler...i have visual c++ 6.0... and what include file do i have to use for that... is it in the standard iostream.... ?
i should have probably thought of that before i wrote that message...i have the code now...
Style is overrated.
- —₽‚¢‰Î -