I need Help with function in C

Started by
5 comments, last by Zahlman 19 years, 7 months ago
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)
Advertisement
If you just want to see if a key is being pressed, use kbhit().
while(!khbit()){//Do stuff here...}
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?
Alfred Reinold Baudisch[Game Development Student] [MAC lover] [Ruby, Ruby on Rails and PHP developer] [Twitter]
thanks for help ^^
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
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.
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*.

This topic is closed to new replies.

Advertisement