This page lists typical questions from D users. Most of them are simply recorded from the newsgroups without much reworking. There are of two other FAQs you might check:
If it's a common error, it may already be on the Error Messages list.
You'll likely get an access violation if you try to print a char in this fashion:
Use std.stdio.writef instead of printf, and std.stdio.writefln to print an extra newline after your output.
If you must use printf, this would be a correct way to do it:
In D, arrays store their length, so character arrays need no terminating zero. In printf, the '%s' indicates a zero terminated string, so it fails when given a normal D string. The '%.*s' tells printf to expect a string preceded by its length. However, printf is still a C function, and so if the string contains embedded zero characters, printf will stop printing the string even before the specified length is reached. In other words, the '%.*s' will print until the length of the string is reached, or a zero is reached, whichever happens first.
The following examples will also work (though less efficient, because a temporary zero terminated string object is constructed):
Sometimes this is seen:
but it is not always reliable, e.g. after:
it will not print "de" but "defghij" because no ending \0 is provided by the slice.
There is a HowTo/printf page giving more information on using printf.
The best way to get an answer to another question is to post it in one of the D newsgroups.