Thread overview
Using writefln with format specifiers in string
Feb 14, 2006
Kramer
Feb 14, 2006
Derek Parnell
Feb 14, 2006
Kramer
Feb 15, 2006
Hasan Aljudy
Feb 15, 2006
Chris Miller
Feb 15, 2006
David Medlock
Feb 15, 2006
Derek Parnell
Feb 16, 2006
Bruno Medeiros
February 14, 2006
I'm hoping someone has run across this before...

I was listing some files in a directory using listdir and then printing out the names using writefln, but the program kept terminating before finishing printing all the contents.  I finally figured out it was because in one of the filenames there was a percent sign.

So, running the following program on DMD 0.146 will produce a FormatError:

# import std.stdio;

# void main(char[][] args) {
#     writefln("AutoDL%3F");
# }

How can I get around this?

I'm running Windows XP SP2 and I tried the command chcp 65001 to set my console to UTF-8 thinking that might be it, but no go.  Then I piped this to a file and lo and behold, the output stopped in the file at the same point on the console.

Any help on this would be much appreciated?

-Kramer


February 14, 2006
On Tue, 14 Feb 2006 18:00:37 +1100, Kramer <Kramer_member@pathlink.com> wrote:


> How can I get around this?

    writefln("%s", FileName);


-- 
Derek Parnell
Melbourne, Australia
February 14, 2006
In article <op.s4yb3wev6b8z09@ginger.vic.bigpond.net.au>, Derek Parnell says...
>
>On Tue, 14 Feb 2006 18:00:37 +1100, Kramer <Kramer_member@pathlink.com> wrote:
>
>
>> How can I get around this?
>
>     writefln("%s", FileName);
>
>
>-- 
>Derek Parnell
>Melbourne, Australia

Ugg, thanks Derek.  Reading the docs help, but reading them carefully helps more. <g>

-Kramer


February 15, 2006
Kramer wrote:
> In article <op.s4yb3wev6b8z09@ginger.vic.bigpond.net.au>, Derek Parnell says...
> 
>>On Tue, 14 Feb 2006 18:00:37 +1100, Kramer <Kramer_member@pathlink.com>  wrote:
>>
>>
>>
>>>How can I get around this?
>>
>>    writefln("%s", FileName);
>>
>>
>>-- 
>>Derek Parnell
>>Melbourne, Australia
> 
> 
> Ugg, thanks Derek.  Reading the docs help, but reading them carefully helps
> more. <g>
> 
> -Kramer
> 
> 

I ran into this before :)
I think there really should be a _standard_ writeraw() or just write() (with no f) which does exactly that ..

void writer( char[] x )
{
    writef("%s", x);
}
February 15, 2006
On Wed, 15 Feb 2006 09:59:48 -0500, Hasan Aljudy <hasan.aljudy@gmail.com> wrote:

> Kramer wrote:
>> In article <op.s4yb3wev6b8z09@ginger.vic.bigpond.net.au>, Derek Parnell says...
>>
>>> On Tue, 14 Feb 2006 18:00:37 +1100, Kramer <Kramer_member@pathlink.com>  wrote:
>>>
>>>
>>>
>>>> How can I get around this?
>>>
>>>    writefln("%s", FileName);
>>>
>>>
>>> -- Derek Parnell
>>> Melbourne, Australia
>>   Ugg, thanks Derek.  Reading the docs help, but reading them carefully helps
>> more. <g>
>>  -Kramer
>>
>
> I ran into this before :)
> I think there really should be a _standard_ writeraw() or just write() (with no f) which does exactly that ..
>
> void writer( char[] x )
> {
>      writef("%s", x);
> }

Yep, and writeln, but you could just use dout.writeString() / dout.writeLine().
February 15, 2006
Chris Miller wrote:
> On Wed, 15 Feb 2006 09:59:48 -0500, Hasan Aljudy <hasan.aljudy@gmail.com>  wrote:
> 
>> Kramer wrote:
>>
>>> In article <op.s4yb3wev6b8z09@ginger.vic.bigpond.net.au>, Derek Parnell  says...
>>>
>>>> On Tue, 14 Feb 2006 18:00:37 +1100, Kramer  <Kramer_member@pathlink.com>  wrote:
>>>>
>>>>
>>>>
>>>>> How can I get around this?
>>>>
>>>>
>>>>    writefln("%s", FileName);
>>>>
>>>>
>>>> -- Derek Parnell
>>>> Melbourne, Australia
>>>
>>>   Ugg, thanks Derek.  Reading the docs help, but reading them carefully  helps
>>> more. <g>
>>>  -Kramer
>>>
>>
>> I ran into this before :)
>> I think there really should be a _standard_ writeraw() or just write()  (with no f) which does exactly that ..
>>
>> void writer( char[] x )
>> {
>>      writef("%s", x);
>> }
> 
> 
> Yep, and writeln, but you could just use dout.writeString() /  dout.writeLine().

Perhaps the formatting should allow '%%' to represent a single percent sign?

-DavidM
February 15, 2006
"David Medlock" <noone@nowhere.com> wrote in message news:dsvouc$1fl5$1@digitaldaemon.com...
> Perhaps the formatting should allow '%%' to represent a single percent sign?

It does.  writefln("5%%") outputs "5%."  The problem is that he wants to print out arbitrary strings which may have single percent signs, and he doesn't want format() interpreting the percent signs as format specifiers.


February 15, 2006
On Wed, 15 Feb 2006 07:59:48 -0700, Hasan Aljudy wrote:

> Kramer wrote:
>> In article <op.s4yb3wev6b8z09@ginger.vic.bigpond.net.au>, Derek Parnell says...
>> 
>>>On Tue, 14 Feb 2006 18:00:37 +1100, Kramer <Kramer_member@pathlink.com> wrote:
>>>
>>>
>>>
>>>>How can I get around this?
>>>
>>>    writefln("%s", FileName);
>>>
>>>
>>>-- 
>>>Derek Parnell
>>>Melbourne, Australia
>> 
>> Ugg, thanks Derek.  Reading the docs help, but reading them carefully helps more. <g>
>> 
>> -Kramer
>> 
> 
> I ran into this before :)
> I think there really should be a _standard_ writeraw() or just write()
> (with no f) which does exactly that ..
> 
> void writer( char[] x )
> {
>      writef("%s", x);
> }

You could always just write such a function and send it to Walter. It might even make it to the official library.

-- 
Derek
(skype: derek.j.parnell)
Melbourne, Australia
"Down with mediocracy!"
16/02/2006 10:12:47 AM
February 16, 2006
Derek Parnell wrote:
> On Wed, 15 Feb 2006 07:59:48 -0700, Hasan Aljudy wrote:
> 
>> Kramer wrote:
>>> In article <op.s4yb3wev6b8z09@ginger.vic.bigpond.net.au>, Derek Parnell says...
>>>
>>>> On Tue, 14 Feb 2006 18:00:37 +1100, Kramer <Kramer_member@pathlink.com>  wrote:
>>>>
>>>>
>>>>
>>>>> How can I get around this?
>>>>    writefln("%s", FileName);
>>>>
>>>>
>>>> -- 
>>>> Derek Parnell
>>>> Melbourne, Australia
>>> Ugg, thanks Derek.  Reading the docs help, but reading them carefully helps
>>> more. <g>
>>>
>>> -Kramer
>>>
>> I ran into this before :)
>> I think there really should be a _standard_ writeraw() or just write() (with no f) which does exactly that ..
>>
>> void writer( char[] x )
>> {
>>      writef("%s", x);
>> }
> 
> You could always just write such a function and send it to Walter. It might
> even make it to the official library.
> 
Yup, I think we should have one such function (write and writeln) in the stdlib.

-- 
Bruno Medeiros - CS/E student
"Certain aspects of D are a pathway to many abilities some consider to be... unnatural."
February 18, 2006
Derek Parnell wrote:

>>I think there really should be a _standard_ writeraw() or just write() (with no f) which does exactly that ..
> 
> You could always just write such a function and send it to Walter. It might
> even make it to the official library.

I wrote write, writeln, read, readln but there was no response.
(i.e. they didn't make into std.stdio, but to din/dout instead)

Will try again. Some day.

--anders

PS.
http://www.digitalmars.com/d/archives/digitalmars/D/15627.html