开发者

Read input from console in OSX

I'm using scanf() to read user input on terminal in a console application. scanf waits开发者_StackOverflow中文版 until the user hits the return key to read. Is there a way to read the user input on each keystroke?


The usual way would be to use the getch function from (the Mac port of) ncurses.

Note that while getchar reads a single character, it still normally does buffered reading, so you need to press 'return'/'enter' before it'll return.


getch() returns the character stream from stdin as it is typed.


char c = getchar();

It should do the trick.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜