Malcolm McLean <> writes:
> On Feb 16, 6:01Â*pm, Keith Thompson <ks...@mib.org> wrote:
>> There's rarely *any* reason to use strncpy(). Â*It's not a "safer"
>> version of strcpy(); it's a quite different function. Â*It can leave
>> the target buffer without a terminating '\0' (i.e., not a string),
>> or it can pad it with multiple needless '\0' bytes.
>>
> It's designed for databases with fixed fields and non-nul terminated
> strings. The padding zeros aren't unnecessary, because often these
> databases do a quick match or lookup by applying some algorithm to the
> whole field.
Yes, the padding zeros are necessary *if* you're dealing with that
kind of data structure.
I suspect that strncpy() is used incorrectly, under the assumption
that it's a "safer" strcpy(), more often than it's used correctly.
IMHO it shouldn't be in the standard library, at least not with
that name.
--
Keith Thompson (The_Other_Keith)
kst- <http://www.ghoti.net/~kst>
Will write code for food.
"We must do something. This is something. Therefore, we must do this."
-- Antony Jay and Jonathan Lynn, "Yes Minister"