input from stdio
hello
i need to know how i can scan only ONE character from stdio. i tried with getchar(), but getchar wont stop getting characters until i press enter. but i really need only the first character of the input. i thought of openeing a stream, and then read with read(), but i dont know how to open that stream to stdio... ya have a good idea? any help is appreciated. thanks raven |
here is an easy way to do it. set up a buffer, then use fgets. ie.
char buf[80]; fgets(buf, 80, stdin); |
Use fcntl to change stdin to not block. Use the O_NONBLOCK flag.
Then use the 'select' statement to wait for a single character to be read from stdin. There is an example on the select man page. What it does not cover is changing stdin not to block. The following lines will cause stdin not to block. Code:
int flags = fcntl( STDIN_FILENO, F_GETFL, 0 ); |
All times are GMT -5. The time now is 11:41 AM. |