Thread overview | |||||||
---|---|---|---|---|---|---|---|
|
January 23, 2007 Reading input lines | ||||
---|---|---|---|---|
| ||||
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?
Bill
--
r * e * @ * o * y * a * c * m
* a * l * z * p * r * . * o *
|
January 23, 2007 Re: Reading input lines | ||||
---|---|---|---|---|
| ||||
Posted in reply to Bill Lear | "Bill Lear" <rael@see.sig.com> wrote in message news:m33b621rvp.fsf@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. |
January 23, 2007 Re: Reading input lines | ||||
---|---|---|---|---|
| ||||
Posted in reply to Jarrett Billingsley | "Jarrett Billingsley" <kb3ctd2@yahoo.com> writes: > "Bill Lear" <rael@see.sig.com> wrote in message news:m33b621rvp.fsf@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 |
January 24, 2007 Re: Reading input lines | ||||
---|---|---|---|---|
| ||||
Posted in reply to Bill Lear | "Bill Lear" <rael@see.sig.com> wrote in message news:m3hcuhzkpe.fsf@lisa.zopyra.com... > 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. Hmm, that doesn't happen under Windows. I guess it's a platform-specific issue. Might want to post it in Bugzilla (I can't find any issues about it there already). |
January 24, 2007 Re: Reading input lines | ||||
---|---|---|---|---|
| ||||
Posted in reply to Jarrett Billingsley Attachments: | Jarrett Billingsley schrieb am 2007-01-24: > "Bill Lear" <rael@see.sig.com> wrote in message news:m3hcuhzkpe.fsf@lisa.zopyra.com... > >> 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. > > Hmm, that doesn't happen under Windows. I guess it's a platform-specific issue. Might want to post it in Bugzilla (I can't find any issues about it there already). http://d.puremagic.com/issues/show_bug.cgi?id=881 Thomas |
Copyright © 1999-2021 by the D Language Foundation