Sign in to follow this  

I need Help with function in C

This topic is 4860 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

What function do I have to use to read from the keyboard, whithout stopping the program? The program was made in C, DOS. for example, if I use "scanf" the function waits for the user to press a key. I Need one function don't do this. (I'm sorry my english is terrible)

Share this post


Link to post
Share on other sites
The function is kbhit(), you need the conio.h header.
A example program:

#include<conio.h>
for(;;) {
if(kbhit()) break;
puts("bla bla");
....
}



ps: I'm brazilian too. do you know www.pdj.com.br or www.unidev.com.br?

Share this post


Link to post
Share on other sites
Uh, if ur writing it in a console window then use:

getch(); this is non-blocking, its what u want
getchar(); this is blocking, not what u want.

hope this helps

ace

Share this post


Link to post
Share on other sites
Quote:
Original post by ace_lovegrove
Uh, if ur writing it in a console window then use:

getch(); this is non-blocking, its what u want
getchar(); this is blocking, not what u want.

hope this helps

ace

I don't believe either of these is in any C or C++ standard. I will not swear to it, but I seem to recall what when last I used them, both were blocking though getchar(), unlike getch(), waited for the user to hit Enter.

Share this post


Link to post
Share on other sites

This topic is 4860 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this