www.digitalmars.com         C & C++   DMDScript  

digitalmars.D - spaces and zeros in writef int format.

Below, I show a program, along with its output.  The writef(%d) and
printf(%d) output differs (which may be okay).  But writef's output
is not consistent for (i<10) and (i>=10).  The printf version seems
to treat this as " %5.5d".  The writef version seems to format with
"%5.5d" (or "% 5.5d"?) for (i<10), but with "%05.5d" for > 10.

If printf() doesn't understand the " " flag described here:

http://www.digitalmars.com/d/std_format.html

. that's okay (and kind of expected... I think).  But for writef()
I think there is at least one bug, that i>10 should have ' '.

Kevin


#import std.stdio;
#import std.file;
#import std.string;
#
#int main()
#{
#    uint i = 0;
#    while(i<20) {
#	writef("[% 5.5d]\n", i);
#	printf("[% 5.5d]\n", i++);
#    }
#    return 0;
#}
#
#[    0]
#[ 00000]
#[    1]
#[ 00001]
#[    2]
#[ 00002]
#[    3]
#[ 00003]
#[    4]
#[ 00004]
#[    5]
#[ 00005]
#[    6]
#[ 00006]
#[    7]
#[ 00007]
#[    8]
#[ 00008]
#[    9]
#[ 00009]
#[00010]
#[ 00010]
#[00011]
#[ 00011]
#[00012]
#[ 00012]
#[00013]
#[ 00013]
#[00014]
#[ 00014]
#[00015]
#[ 00015]
#[00016]
#[ 00016]
#[00017]
#[ 00017]
#[00018]
#[ 00018]
#[00019]
#[ 00019]
#
Oct 05 2004