Reading input lines

Bill Lear rael at see.sig.com
Tue Jan 23 10:01:17 PST 2007


"Jarrett Billingsley" <kb3ctd2 at yahoo.com> writes:
> "Bill Lear" <rael at see.sig.com> wrote in message 
> news:m33b621rvp.fsf at pppp.zopyra.com...
> >I am trying to read lines from stdin and echo them to stdout.
> >
> > I have come up with this:
> >
> > import std.stdio;
> > import std.cstream;
> > import std.string;
> >
> > void main () {
> >    while (!din.eof()) {
> >        char[] line = din.readLine();
> >        if (line == null) continue;
> >        writefln("%s", line);
> >    }
> > }
> >
> > but am confused why I would need to check for null.  Is there
> > a better way to do this?
> 
> Do you?  I took out the null check and it works fine, unless you're getting 
> errors on Linux or something. 

Yes, this is under Linux, dmd version 1.00.  If I run the program,
with the text of the program as input, without the null check, it
prints out an additional blank line for every line in the file.


Bill
-- 
r a e l @
z o p y r a .
c o m



More information about the Digitalmars-d mailing list