www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.learn - How to write printf(...) like function

reply Cris <central_p hotmail.com> writes:
     Where is what I'm trying to do is to make a print function that outputs
both 
to a console and to a file but I have get a std.format runtime error. Any ideas 
how to do it?


     void printTo(...)
     {
         char[] string;

         void putc(dchar c)
         {
             string ~= c;
         }

         std.format.doFormat(&putc, _arguments, _argptr);

             printf(string ~= "\0"); //  std.c.stdio
             file.printf(string);
     }
Mar 08 2006
parent reply Chris Sauls <ibisbasenji gmail.com> writes:
Cris wrote:
     Where is what I'm trying to do is to make a print function that 
 outputs both to a console and to a file but I have get a std.format 
 runtime error. Any ideas how to do it?
 
 
     void printTo(...)
     {
         char[] string;
 
         void putc(dchar c)
         {
             string ~= c;
         }
 
         std.format.doFormat(&putc, _arguments, _argptr);
 
             printf(string ~= "\0"); //  std.c.stdio
             file.printf(string);
     }
The attached file is my own test and partial rewrite of your function, which essentially works. -- Chris Nicholson-Sauls
Mar 08 2006
parent Cris <central_p hotmail.com> writes:
Thank you for the help! Your code works now.

Was the problem the standard C printf?

 
 The attached file is my own test and partial rewrite of your function, 
 which essentially works.
 
 -- Chris Nicholson-Sauls
 
Mar 09 2006