Issue with writefln ?

BCS BCS at pathlink.com
Wed Apr 4 15:24:50 PDT 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.



More information about the Digitalmars-d mailing list