read single characters from stdin

Adam D. Ruppe destructionator at gmail.com
Wed Sep 26 11:06:03 PDT 2012


On Wednesday, 26 September 2012 at 17:51:03 UTC, Thomas Koch 
wrote:
> How can I read single characters?

The way I'd do it is with the C call fgetc(stdin). You can do it 
in D the same way if you import core.stdc.stdio;

But, if you are on Linux, it isn't going to be that simple. The 
Linux terminal/operating system will buffer input, not sending 
any data to you until the user presses enter.

You'll probably want to use a library like ncurses on linux... 
you can do without too, turning on raw mode to the terminal I 
think, but I don't remember how to do it right now. Are you on 
Linux or Windows?

(I'm pretty sure it just works on windows but it's been a while 
since I've done an app like this.)


More information about the Digitalmars-d-learn mailing list