Shao Miller wrote:
>
> On 2/20/2012 23:16, pete wrote:
> > Shao Miller wrote:
> >
> >> My impression is that in:
> >>
> >> char foo[] = "foo";
> >> char bar[3] = "bar";
> >> char baz[10] = "baz";
> >>
> >> each of these could be roughly equivalent to:
> >>
> >> char foo[sizeof "foo"];
> >> char bar[3];
> >> char baz[10];
> >>
> >> strncat(foo, "foo", sizeof "foo");
> >> strncat(bar, "bar", 3);
> Somehow, I completely was confusing 'strncpy' with 'strncat', here. 
> Please substitute 'strncpy' in place of 'strncat' in my post.
Of
> course, that makes it irrelevant
> to Keith's immediately-preceding post.
>
> Thank you for the correction, pete!
You're welcome.
What I don't about the idea of using strncpy instead of strcpy,
is that learning to use strncpy instead of strcpy,
seems to me to be more complicated
than learning to use strcpy properly.
The n parameter of strncpy makes it harder to forget
that the size of something must be taken into account.
But anyone who would have trouble remembering
how to use strcpy correctly,
might also have trouble remembering
that if n is less than (1 + source string length)
then the resulting strncpy write, will not be a string.
I've always been comfortable using strcpy.
--
pete