digitalmars.D.learn - my first D program, what is wrong with it?
- dominik (20/20) Sep 27 2007 ok, I've just unzipped dm and dmd, and I have tried to write my first
- BCS (3/26) Sep 27 2007 IIRC writefln starte outputting at the current location and appens a new...
- Frits van Bommel (6/34) Sep 27 2007 The middle one is writef, not writefln.
- BCS (4/29) Sep 27 2007 that is how I was reading it. The error I think is in question is that t...
- Frits van Bommel (6/37) Sep 27 2007 Oh wait, I must've misread the original post. Yes, that's what happens
- Gilles G. (16/42) Sep 27 2007 Well, I think on windows \r also clears the current line...
- dominik (6/8) Sep 27 2007 exactly, I just did that and it works. Thanks for help. I am writing ton...
ok, I've just unzipped dm and dmd, and I have tried to write my first trivial D program - just to get started (below is the code I wrote). It works, from the first try :) However, it behaves em weird. First writefln works like it is supposed to, last one also, however writef should just write in place haaaa and the number (hence the \r). But, when printing in place is done, and the last writefln fires off, line where writef wrote to disappears. How, why? I'm on windows XP if that matters ---------------------------------------------- import std.stdio; int main(char[][] args) { writefln("==================="); for (int i = 0; i < 50000; i++) { writef("haaaaa ", i, " \r"); } writefln("==================="); return 0; } ----------------------------------------------
Sep 27 2007
Reply to dominik,ok, I've just unzipped dm and dmd, and I have tried to write my first trivial D program - just to get started (below is the code I wrote). It works, from the first try :) However, it behaves em weird. First writefln works like it is supposed to, last one also, however writef should just write in place haaaa and the number (hence the \r). But, when printing in place is done, and the last writefln fires off, line where writef wrote to disappears. How, why? I'm on windows XP if that matters ---------------------------------------------- import std.stdio; int main(char[][] args) { writefln("==================="); for (int i = 0; i < 50000; i++) { writef("haaaaa ", i, " \r"); } writefln("==================="); return 0; } ----------------------------------------------IIRC writefln starte outputting at the current location and appens a newline at the end. It does not ever add a newline at the start.
Sep 27 2007
BCS wrote:Reply to dominik,The middle one is writef, not writefln. And I think the point of this program is not to put newlines between the outputs, but to keep overwriting the last line (as a progress indicator, I guess). Which is exactly what it does on Linux by the way, with both DMD and GDC.ok, I've just unzipped dm and dmd, and I have tried to write my first trivial D program - just to get started (below is the code I wrote). It works, from the first try :) However, it behaves em weird. First writefln works like it is supposed to, last one also, however writef should just write in place haaaa and the number (hence the \r). But, when printing in place is done, and the last writefln fires off, line where writef wrote to disappears. How, why? I'm on windows XP if that matters ---------------------------------------------- import std.stdio; int main(char[][] args) { writefln("==================="); for (int i = 0; i < 50000; i++) { writef("haaaaa ", i, " \r"); } writefln("==================="); return 0; } ----------------------------------------------IIRC writefln starte outputting at the current location and appens a newline at the end. It does not ever add a newline at the start.
Sep 27 2007
Reply to Frits,BCS wrote:that is how I was reading it. The error I think is in question is that the writfln replaces the last line from the writef. I haven't run the code so I could be totaly off base here.Reply to dominik,The middle one is writef, not writefln. And I think the point of this program is not to put newlines between the outputs, but to keep overwriting the last line (as a progress indicator, I guess). Which is exactly what it does on Linux by the way, with both DMD and GDC.---------------------------------------------- import std.stdio; int main(char[][] args) { writefln("==================="); for (int i = 0; i < 50000; i++) { writef("haaaaa ", i, " \r"); } writefln("==================="); return 0; } ----------------------------------------------IIRC writefln starte outputting at the current location and appens a newline at the end. It does not ever add a newline at the start.
Sep 27 2007
BCS wrote:Reply to Frits,Oh wait, I must've misread the original post. Yes, that's what happens (I just didn't realize that was the problem -- I thought he didn't see the counting at all) dominik: Try adding a writefln() right after the loop, or prepending "\n" to the last string.BCS wrote:that is how I was reading it. The error I think is in question is that the writfln replaces the last line from the writef.Reply to dominik,The middle one is writef, not writefln. And I think the point of this program is not to put newlines between the outputs, but to keep overwriting the last line (as a progress indicator, I guess). Which is exactly what it does on Linux by the way, with both DMD and GDC.---------------------------------------------- import std.stdio; int main(char[][] args) { writefln("==================="); for (int i = 0; i < 50000; i++) { writef("haaaaa ", i, " \r"); } writefln("==================="); return 0; } ----------------------------------------------IIRC writefln starte outputting at the current location and appens a newline at the end. It does not ever add a newline at the start.
Sep 27 2007
Well, I think on windows \r also clears the current line... So instead you should use something like: import std.stdio; int main(char[][] args) { writefln("==================="); for (int i = 0; i < 50000; i++) { writef("\rhaaaaa ", i); } writefln("\n==================="); return 0; } This should work, but notice that I did not try it... dominik Wrote:ok, I've just unzipped dm and dmd, and I have tried to write my first trivial D program - just to get started (below is the code I wrote). It works, from the first try :) However, it behaves em weird. First writefln works like it is supposed to, last one also, however writef should just write in place haaaa and the number (hence the \r). But, when printing in place is done, and the last writefln fires off, line where writef wrote to disappears. How, why? I'm on windows XP if that matters ---------------------------------------------- import std.stdio; int main(char[][] args) { writefln("==================="); for (int i = 0; i < 50000; i++) { writef("haaaaa ", i, " \r"); } writefln("==================="); return 0; } ----------------------------------------------
Sep 27 2007
"Gilles G." <schaouette free.fr> wrote in message news:fdh95q$bir$1 digitalmars.com...Well, I think on windows \r also clears the current line... So instead you should use something like:exactly, I just did that and it works. Thanks for help. I am writing tons and tons of "scripts" as command line utilites with PHP both for windows and linux every day, so I was used to the way that works there. Thanks again guys!
Sep 27 2007