www.digitalmars.com         C & C++   DMDScript  

digitalmars.D - reading UTF-8 character from stdin

reply Zoda <zoda vuhuv.com> writes:
Hi i need to read exactly one character from stdin, but i could 
not found a proper way of doing it, how can i do that?
Aug 05
next sibling parent reply Serg Gini <kornburn yandex.ru> writes:
On Tuesday, 5 August 2025 at 12:15:40 UTC, Zoda wrote:
 Hi i need to read exactly one character from stdin, but i could 
 not found a proper way of doing it, how can i do that?
```d void main() { import std.stdio; char x; readf!"%c"(x); writeln(x); } ```
Aug 05
parent reply Zoda <zoda vuhuv.com> writes:
On Tuesday, 5 August 2025 at 12:57:29 UTC, Serg Gini wrote:
 On Tuesday, 5 August 2025 at 12:15:40 UTC, Zoda wrote:
 Hi i need to read exactly one character from stdin, but i 
 could not found a proper way of doing it, how can i do that?
```d void main() { import std.stdio; char x; readf!"%c"(x); writeln(x); } ```
Sorry but it doesn't work properly in Windows, i tried.
Aug 05
parent Serg Gini <kornburn yandex.ru> writes:
On Tuesday, 5 August 2025 at 13:23:27 UTC, Zoda wrote:
 On Tuesday, 5 August 2025 at 12:57:29 UTC, Serg Gini wrote:
 On Tuesday, 5 August 2025 at 12:15:40 UTC, Zoda wrote:
 Hi i need to read exactly one character from stdin, but i 
 could not found a proper way of doing it, how can i do that?
```d void main() { import std.stdio; char x; readf!"%c"(x); writeln(x); } ```
Sorry but it doesn't work properly in Windows, i tried.
You need then `stdin.readf!" %c"(x);` It worked for me with `echo "123" | .\app.exe` But this is the simplest example. Support for different UTF symbols could require more work
Aug 05
prev sibling parent monkyyy <crazymonkyyy gmail.com> writes:
On Tuesday, 5 August 2025 at 12:15:40 UTC, Zoda wrote:
 Hi i need to read exactly one character from stdin, but i could 
 not found a proper way of doing it, how can i do that?
id probably just do ```d import std; void main(){ foreach(dchar c;stdin.byLineCopy.map!(a=>a.array).joiner){ c.writeln; } } ``` Everything will be fairly hacky
Aug 05