reading formatted strings: readf("%s", &stringvar)
Andrei Alexandrescu
SeeWebsiteForEmail at erdani.org
Mon Mar 26 07:41:41 PDT 2012
On 3/26/12 5:55 AM, Tyro[17] wrote:
> You can achieve the same with:
>
> readf(" %s\n", &s2);
>
> My goal however, is not to read one line of information. Rather, it is to
> read multiple lines of information from standard input. I get close to
> being able to do so if i don't including "\n" as a part of my format string
> or if I changing your suggestion to
>
> while (!stdin.eol()) {
> s2 = chomp(readln());
> }
>
> but again I run into the predicament was before, a need to close the
> the stream with Ctrl-D/Ctrl-Z.
I made the decision for the current behavior while implementing readf.
Basically I tried to avoid what I think was a mistake of scanf, i.e.
that of stopping string reading at the first whitespace character, which
is fairly useless.
Over the years scanf was improved with %[...] which allows reading
strings with any characters in a set.
Anyway, if I understand correctly, there's no way to achieve what you
want unless you read character-by-character and define your own control
character. There's no out-of-band character that means "end of this
input, but not that of the file".
Andrei
More information about the Digitalmars-d
mailing list