On Thu, 05 Jun 2008 20:21:29 +0000, Walter Roberson wrote:
printf("%.*s", n, TheCharPointer);
[...]
Also, the behaviour is not explicitly defined (at least not in
C89) if the string pointed to does not contain a 0 before the end of the
object:
<nit>If the array pointed to does not contain a 0 before the end of the
object, it's not a string.</nit>
you are still technically responsible for passing a string in
the parameter position, even if you've told it to only copy so many
characters out of the string.
Really? Could you show what C89 says? I don't have a copy of it, but I'm
interested because both a draft and text based on the official standard do
make it clear '\0' is not required, and the text in both is largely
identical:
C89 draft:
"Characters from the array are written up to (but not including) any
terminating null character; if the precision is specified, no more than
that many characters are written. If the precision is not specified or is
greater than the size of the array, the array shall contain a null
character."
SUSv2, based on C89:
"Bytes from the array are written up to (but not including) any
terminating null byte. If the precision is specified, no more than that
many bytes are written. If the precision is not specified or is greater
than the size of the array, the array must contain a null byte."
I would be very surprised if this text was present in the drafts, dropped
from the C89 standard, only to be added again afterwards by both SUS and
C99.