Jump to content
  • Advertisement
Sign in to follow this  
fer_aline

I need Help with function in C

This topic is 5046 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
Advertisement
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
Basically all IO is blocking; if there's no data available, then it has to wait for some to arrive.

getch() is not *line-buffered*.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!