On Saturday, 7 April 2012 at 22:21:36 UTC, Jonas wrote:
5) What's wrong with this program? Is it that `printf` doesn't
understand D strings? If so, how do I use D strings in string
formatting?
import std.stdio;
string foo() { return "foobar"; }
int main() {
printf("%s\n", foo());
return 0;
}
You can use toStringz() from std.string to convert D strings to
null terminated strings when you need to interface with C
functions. But in this case, writeln() would be the simplest
solution. It would be only:
writeln(foo());
Instead of:
printf("%s\n", toStringz(foo()));
I'm a newbie in D too, so correct me if there is anything wrong.