Question regarding readf

Adam D. Ruppe destructionator at gmail.com
Mon Apr 22 22:23:42 UTC 2019


On Monday, 22 April 2019 at 20:45:54 UTC, Andre Pany wrote:
> The code from the example does not work,
> writeln is never executed.

For "%s" with a string argument, it reads ALL of stdin into that 
string. This means you need to send an end-of-file indicator to 
the program. ctrl+z on Windows does this, and ctrl+d can on Linux 
(you might have to hit it twice there; it doesn't technically 
send end of file, but can be read as it by the program if there 
is no other input pending in the buffer).

This is quite bizarre for new users, I agree, but it isn't 
technically invalid.

(my personal feeling though is readf is just a pile of confusion 
and should almost never be used. I hate that it is introduced so 
early in most tutorials... I'd rather have it in an appendix for 
special cases only rather than like page 3.)


More information about the Digitalmars-d-learn mailing list