www.digitalmars.com         C & C++   DMDScript  

digitalmars.D - error in D website demo

reply user domain.invalid writes:
Hi,

I just started playing with D and noticed an error when I build the 
"Hello World" program on the website at 
http://www.digitalmars.com/d/2.0/index.html. Such errors are often 
perplexing to new users :-).

Line 23 of the demo is:

         writefln(cl.argnum, cl.suffix, " arg: %s", cl.argv);

But it produces incorrect output:

Hello World, Reloaded
1st arg: %sC:\Documents and Settings\DennisC\My Documents\My Source 
Files\D\hello\hello.exe

Notice the %s floating in the output.

This is because the library was changed as documented at 
http://www.digitalmars.com/d/2.0/phobos/std_stdio.html. Its description 
of writef() says:

IMPORTANT:
New behavior starting with D 2.006: unlike previous versions, writef 
(and also writefln) only scans its first string argument for format 
specifiers, but not subsequent string arguments. This decision was made 
because the old behavior made it unduly hard to simply print string 
variables that occasionally embedded percent signs.


So it seems to me that this line should be rewritten as either:

         writefln(cl.argnum, cl.suffix, " arg: ", cl.argv);

or

         writefln("%d%s arg: %s", cl.argnum, cl.suffix, cl.argv);

to be compatible with the current library behavior.

HTH
Dennis Cote
Feb 05 2008
parent reply Walter Bright <newshound1 digitalmars.com> writes:
Thanks. Fixed.
Feb 05 2008
parent reply "Saaa" <empty needmail.com> writes:
char[] str;
char[] str1 = "abc";
str[0] = 'b';        // error, "abc" is read only, may crashAs said a few 
posts below, this one is wrong as well (as far as I know) 
Feb 05 2008
next sibling parent "Saaa" <empty needmail.com> writes:
I love monologues :/ 
Feb 06 2008
prev sibling parent reply Moritz Warning <moritzwarning _nospam_web.de> writes:
On Wed, 06 Feb 2008 08:29:22 +0100, Saaa wrote:

 char[] str;
 char[] str1 = "abc";
 str[0] = 'b';        // error, "abc" is read only, may crashAs said a
 few posts below, this one is wrong as well (as far as I know)
Where do you saw this?
Feb 06 2008
parent "Saaa" <empty needmail.com> writes:
"Moritz Warning" <moritzwarning _nospam_web.de> wrote in message 
news:foddam$25te$1 digitalmars.com...
 On Wed, 06 Feb 2008 08:29:22 +0100, Saaa wrote:

 char[] str;
 char[] str1 = "abc";
 str[0] = 'b';        // error, "abc" is read only, may crashAs said a
 few posts below, this one is wrong as well (as far as I know)
Where do you saw this?
http://www.digitalmars.com/d/1.0/arrays.html special array types
Feb 06 2008