my first D program, what is wrong with it?

Frits van Bommel fvbommel at REMwOVExCAPSs.nl
Thu Sep 27 14:40:22 PDT 2007


BCS wrote:
> 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.

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.


More information about the Digitalmars-d-learn mailing list