Help plz

This is a discussion on Help plz within the C++ Programming forums, part of the General Programming Boards category; does anyone know code that would grab input from the user but not if there is none entered... unlike the ...

  1. #1
    Registered User Ajsan's Avatar
    Join Date
    Dec 2003
    Posts
    55

    Unhappy Help plz

    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.


  2. #2
    and the hat of wrongness Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,668
    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 support http://www.ukip.org/ as the first necessary step to a free Europe.

  3. #3
    Registered User Ajsan's Avatar
    Join Date
    Dec 2003
    Posts
    55

    Talking Thx

    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.

  4. #4
    and the hat of wrongness Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,668
    > 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.
    I support http://www.ukip.org/ as the first necessary step to a free Europe.

  5. #5
    WDT
    WDT is offline
    Tha 1 Sick RAT
    Join Date
    Dec 2003
    Posts
    271

    Angry

    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 )

  6. #6
    and the hat of wrongness Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,668
    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?
    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;
    }
    If you want to replace check_for_key_press() with check_for_key_press_with_timeout() then that's up to you.
    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.
    I support http://www.ukip.org/ as the first necessary step to a free Europe.

  7. #7
    Registered User Ajsan's Avatar
    Join Date
    Dec 2003
    Posts
    55

    sry

    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.

    - 冷たい火 -

  8. #8
    and the hat of wrongness Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,668
    > 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.
    I support http://www.ukip.org/ as the first necessary step to a free Europe.

  9. #9
    Registered User Ajsan's Avatar
    Join Date
    Dec 2003
    Posts
    55

    thank you

    okay thx.
    Style is overrated.

    - 冷たい火 -

  10. #10
    Registered User Ajsan's Avatar
    Join Date
    Dec 2003
    Posts
    55

    that doesn't work

    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.

    - 冷たい火 -

  11. #11
    Registered User
    Join Date
    Feb 2004
    Posts
    46
    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.
    Code:
    _AX = 0x00;
    geninterrupt(0x16);
    On Unix, some variation of an ioctl will do what you want:
    Code:
    int n;
    ioctl(0, FIONREAD, &n);
    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.

  12. #12
    Registered User Ajsan's Avatar
    Join Date
    Dec 2003
    Posts
    55

    thx

    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.

    - 冷たい火 -

  13. #13
    Registered User
    Join Date
    Sep 2003
    Posts
    135

    Re: thx

    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.... ?
    Check the extensive online help that comes with VC++ 6.0. It will answer this and many other basic questions.

  14. #14
    Registered User Ajsan's Avatar
    Join Date
    Dec 2003
    Posts
    55

    thx

    i should have probably thought of that before i wrote that message...i have the code now...
    Style is overrated.

    - 冷たい火 -

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. can any1 plz make this assignment
    By jean in forum C Programming
    Replies: 17
    Last Post: 05-13-2009, 09:19 PM
  2. plz help me...
    By sweetchakri in forum C Programming
    Replies: 1
    Last Post: 03-03-2009, 10:50 PM
  3. [Request] Need Help Plz
    By TylerD in forum Tech Board
    Replies: 4
    Last Post: 01-03-2009, 08:54 AM
  4. Anyone plz help me
    By Rose_Flowers in forum A Brief History of Cprogramming.com
    Replies: 1
    Last Post: 09-17-2003, 12:01 PM
  5. help plz plz
    By nsssn73 in forum C++ Programming
    Replies: 2
    Last Post: 06-03-2002, 08:44 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21