Kelvin Moss wrote:
Am I guaranteed a null terminated string after using strncat
if my destination buffer is big enough for n + 1 characters?
...
strncat(dest, source, n);
Is dest[n] == 0 after above statement (assuming dest[n]
doesn't cause any buffer overrun)
Yes. Note that, in a sense, strncat over teriminates the
destination if there is more room than required. Consider...
char dest[10];
strncpy(dest, "hello", sizeof dest);
Not only will dest[5] be a null byte, but so will dest[6]
through dest[9].
The strncat function wasn't designed for concatenation, it
was designed for old style fix width data fields where
excess bytes need to be zero-ed.
--
Peter