Path: utzoo!utgpu!jarvis.csri.toronto.edu!mailrus!cs.utexas.edu!usc!srhqla!tcm From: tcm@srhqla.SR.COM (Tim Meighan) Newsgroups: comp.lang.c Subject: Re: strncpy Keywords: strncpy null termination Message-ID: <1231@srhqla.SR.COM> Date: 21 Dec 89 17:56:43 GMT Reply-To: tcm@srhqla.SR.COM (Tim Meighan) Organization: Silent Radio, Los Angeles Lines: 28 In article <11509@csli.Stanford.EDU> poser@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!"