How to use sprintf

Justin Hanekom justin.hanekom at gmail.com
Sun Apr 24 14:22:09 PDT 2011


Hi all,

I have what should be an *extremely* simple question that Im banging my head against: how to use
sprintf to format something to a string.

I have tried:
  import std.stdio;
  ...
  auto buffer = new char[12];
  auto chars_written = sprintf(cast(char *) buffer, "%d", 12345);
  writeln(chars_written);
and various other ways of getting the buffer into sprintf, but no matter what I do the program seems to
die when sprintf is called.

What I'm ultimately trying to do here is format a number with thousands separated by commas.

Any idea?

Thanks, Justin


More information about the Digitalmars-d mailing list