Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Newbie: How to read directly from stdin without \n

Status
Not open for further replies.

MattHHDE

Programmer
Oct 25, 2004
2
DE
Hi
can someone tell me how to read a char from the stdin without waiting for the user pressing return?
I want to start/stop a thread with pressing 1 on the console but the needed return is frustrating...
 
Such a feature is non-standard.
You need to say which OS and compiler you're using.


--
 
Well... a little difficult to answere :)
I am writing it with the eclipse CDT (currently under windows), useing cygwin and the gcc compiler. The targetsystem would be QNX.
 
Well then you're going to have to resort to conditional compilation.

Code:
#if defined(QNX)
int myReadChar ( int fd ) {
}
#elif defined(CYGWIN)
int myReadChar ( int fd ) {
}
#else
#error unknown operating system
#endif

Where you would compile this module using the appropriate
Code:
gcc -c -DQNX prog.c
gcc -c -DCYGWIN prog.c

As for what goes inside each of those functions....

This may work for cygwin - see my answer in this post

As for QNX, I suggest a good read of the manual.

--
 
CYGWIN will require you to put the terminal in "raw mode" or use curses (does curses require C++ or will it work in C) or other additional library. If you have to put the terminal in raw mode, you will become responsible for echo-ing the chars read to the output stream.
 
> does curses require C++ or will it work in C?

Yes, it's a C library.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top