Thread overview
Issue with writefln ?
Apr 04, 2007
0ffh
Apr 04, 2007
Marcin Kuszczak
Apr 04, 2007
BCS
Apr 04, 2007
0ffh
Apr 04, 2007
Dan
Apr 04, 2007
0ffh
April 04, 2007
Hija,

I get an exception (std.format string) thrown
after I read a file with std.file.read and try
to writefln its content, while it works fine
with toStringz and printf.

Code is something like:

char[] s=cast(char[])stf.file.read("name.ext");
printf("<%s>\n",toStringz(s)); // works fine
writelnf("<",s,">"); // exception generated

I have shrunk the file to:

garble"%"urgh

I do strongly suppose that the problem lies
somewhere in part saying "%" , but... ?

Is this a Hemiptera? :-)

Regards,

  frank
April 04, 2007
0ffh wrote:

> 
> Hija,
> 
> I get an exception (std.format string) thrown
> after I read a file with std.file.read and try
> to writefln its content, while it works fine
> with toStringz and printf.
> 
> Code is something like:
> 
> char[] s=cast(char[])stf.file.read("name.ext");
> printf("<%s>\n",toStringz(s)); // works fine
> writelnf("<",s,">"); // exception generated
> 
> I have shrunk the file to:
> 
> garble"%"urgh
> 
> I do strongly suppose that the problem lies
> somewhere in part saying "%" , but... ?
> 
> Is this a Hemiptera? :-)
> 
> Regards,
> 
>    frank

I think that your file has non UTF-8 characters inside (characters with
codes >= 128).

char[] is in D UTF8 sequence.

You probably should first recode your file.

-- 
Regards
Marcin Kuszczak (Aarti_pl)
-------------------------------------
Ask me why I believe in Jesus - http://zapytaj.dlajezusa.pl (en/pl)
Doost (port of few Boost libraries) - http://www.dsource.org/projects/doost/
-------------------------------------

April 04, 2007
0ffh wrote:
> 
> Hija,
> 
> I get an exception (std.format string) thrown
> after I read a file with std.file.read and try
> to writefln its content, while it works fine
> with toStringz and printf.
> 
> Code is something like:
> 
> char[] s=cast(char[])stf.file.read("name.ext");
> printf("<%s>\n",toStringz(s)); // works fine
> writelnf("<",s,">"); // exception generated
> 
> I have shrunk the file to:
> 
> garble"%"urgh
> 
> I do strongly suppose that the problem lies
> somewhere in part saying "%" , but... ?
> 
> Is this a Hemiptera? :-)
> 
> Regards,
> 
>   frank

unless it is being used from a format string, all char[] are assumed to be format strings. Try this:

writelnf("<%s>",s);

In general it is bad practice to have a non literal string used in writef/writelnf unless you only reference it by way of a format string.
April 04, 2007
BCS wrote:
> unless it is being used from a format string, all char[] are assumed to be format strings. Try this:
> 
> writelnf("<%s>",s);
> 
> In general it is bad practice to have a non literal string used in writef/writelnf unless you only reference it by way of a format string.

Works and is soundly explained! Cheers to you, good sir! :)

April 04, 2007
hehe, i am your neighbor :)
I am driving everyday through LB.
Frank
http://www.frappr.com/d
April 04, 2007
Frank Benoit (keinfarbton) wrote:
> hehe, i am your neighbor :)
> I am driving everyday through LB.
> Frank
> http://www.frappr.com/d

I have sent pm to you, but no reply yet,
hope I got the despamming right...
otherwise you may want to mail me?

Regards, Frank

p.s.
The address /does/ actually work, as of
now... otherwise try frank at etc...
April 04, 2007
BCS Wrote:
> unless it is being used from a format string, all char[] are assumed to be format strings. Try this:
> 
> writelnf("<%s>",s);
> 
> In general it is bad practice to have a non literal string used in writef/writelnf unless you only reference it by way of a format string.

Wow!  I never thought of that.  (sincerely)   I'll be sure to do that in the future.