Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Sign In with Facebook Sign In with Google Sign In with OpenID

Categories

We have migrated to a new platform! Please note that you will need to reset your password to log in (your credentials are still in-tact though). Please contact lee@programmersheaven.com if you have questions.
Welcome to the new platform of Programmer's Heaven! We apologize for the inconvenience caused, if you visited us from a broken link of the previous version. The main reason to move to a new platform is to provide more effective and collaborative experience to you all. Please feel free to experience the new platform and use its exciting features. Contact us for any issue that you need to get clarified. We are more than happy to help you.

wait function help

cobastonecobastone Posts: 1Member
I'm writing a function that waites until the user selects the enter key then proceeds on a windows system . the only isseue is I cannot use getchar() or scanf() they both open a stdio windows which closes my user window.
I was hoping to access the STDIO.H and perhaps find the keyboard function.
and obtain the character that way. However upon looking in the ansi library the getchar() definition was gibberish.

Does anyone have such a function that simply waites until the user hit the enter key. Then proceeds?

Comments

  • LundinLundin Posts: 3,711Member
    It all depends on what OS you are using. The only way to do it in standard C is through getchar().
  • tritoustritous Posts: 1Member
    : I'm writing a function that waites until the user selects the enter
    : key then proceeds on a windows system . the only isseue is I cannot
    : use getchar() or scanf() they both open a stdio windows which closes
    : my user window.
    : I was hoping to access the STDIO.H and perhaps find the keyboard
    : function.
    : and obtain the character that way. However upon looking in the ansi
    : library the getchar() definition was gibberish.
    :
    : Does anyone have such a function that simply waites until the user
    : hit the enter key. Then proceeds?
    :

    while( !kbhit() ){}

    Found it in a snippet of sample code I saw a while back. Crude, but it should work in GUI, I know it works in a CLI. You could easily add a sleep/wait function of some sort in there to avoid devouring the cpu. I suspect it needs windows.h so it's not platform independant but a couple of compiler if statements and a check for the platform you are on will work if you can find the equivilent unix/other functions you need.


  • LundinLundin Posts: 3,711Member
    1. The original post was made 3 months ago.

    2. kbhit() is a non-standard Borland function that will only work on Borland compilers for DOS, and those compilers have been obsolete for 13 years. It will not work on a windows compiler.
  • Ed HallEd Hall Posts: 395Member
    [code]
    MessageBox(NULL, "Press Enter to continue", "Pause", MB_OK);
    [/code]

    will display a MessageBox in the center of the screen, with "Pause" for the title, "Press Enter to continue" for the Text and a defaulted "OK" button that will close the MessageBox and continue with the program if either the Enter key or spacebar are pressed, or the button is selected with the mouse.

    Take Care,
    Ed
Sign In or Register to comment.