strncpy
Tim Meighan
tcm at srhqla.SR.COM
Fri Dec 22 04:56:43 AEST 1989
In article <11509 at csli.Stanford.EDU> poser at csli.Stanford.EDU
(Bill Poser) writes:
> So I claim that strncpy is mis-designed and should null-terminate.
> Any comments?
Well, I generally make sure the array I'm copying INTO is larger than
what I'm copying. That way the null terminator gets copied in as well
and everything is cool.
I could make the argument that it's poor programming practice to be
copying strings into arrays that aren't large enough to hold them, and
that strncpy() is merely making the best of a bad situation. You could
probably counter with an excellent example of a real-life instance where
the situation arises. I would then counter that if you're doing things
that are that sophisticated, it's a good time to write your own function
that works just like strncpy(), but that does string termination the
way you want it to be done!
Personally, I think strncpy() works just fine as is. As I said, I
have never had a situation where I needed it to do anything other
than what it does.
Tim Meighan
SilentRadio
"The text strings were shifted in memory with care . . .
with the hope that NULL TERMINATOR soon would be there!"
More information about the Comp.lang.c
mailing list