reading formatted strings: readf("%s", &stringvar)

Tyro[17] nospam at home.com
Tue Mar 27 05:59:26 PDT 2012


On Monday, 26 March 2012 at 21:20:00 UTC, Ali Çehreli wrote:
> On 03/26/2012 02:12 PM, Tyro[17] wrote:
>
> > I don't want to provide an explicit terminator, but instead
> > rely on Ctrl-D/Ctrl-Z to do the job while being able to
> > continue processing read request. As explained by Andrei,
> > this is not possible. But in my mind if the stdin stream
> > can be opened once, it can be opened again. What is the
> > negative effect of testing if it is closed and reopening it
> > on entering readf? Especially since there is a unique
> > implementation of readf to deal with input from stdin.
> >
> > What is wrong with implementing reopen() in File for
> > specific use with stdin and then implementing readf
> > like this:
> >
> > uint readf(A...)(in char[] format, A args)
> > {
> > if(stdin.eof) stdin.reopen();
> > return stdin.readf(format, args);
> > }
> >
> > Andrew
>
> That doesn't fit the way standard input and output streams 
> work. These streams are bound to the application from the 
> environment that has started them. The program itself does not 
> have a way of manipulating how these streams are ended or 
> connected.
>
> Imagine that your program's stdin if piped from the output of 
> another process:
>
>   other | yours
>
> Once 'other' finishes with its output, that's the end of the 
> input of 'yours'. 'yours' cannot communicate to the environment 
> that it would like to continue reading more.

Thanks for that explanation. I am only now understanding the
problem.

> What you are asking for could be achieved only if both the 
> environment and the program agreed that this would be the case.

Not really, we can "borrow" Ctrl-D form the OS until our input is
complete. Please see response to Andrei.

> Maybe I am missing something but that has been standard on many 
> environments.
>
> Ali




More information about the Digitalmars-d mailing list