Path: utzoo!utgpu!jarvis.csri.toronto.edu!cs.utexas.edu!asuvax!hrc!phobos!ellisond From: ellisond@phobos.UUCP (Dell Ellison) Newsgroups: comp.lang.c Subject: Re: strncpy Summary: Actually ... Message-ID: <48314938.f69e@phobos.UUCP> Date: 22 Jan 90 20:09:02 GMT References: <11527@csli.Stanford.EDU> <000003Q@cdis-1.UUCP> <11616@csli.Stanford.EDU> Organization: gte Lines: 34 In article <11616@csli.Stanford.EDU>, poser@csli.Stanford.EDU (Bill Poser) writes: > In article <000003Q@cdis-1.UUCP> tanner@cdis-1.UUCP (Dr. T. Andrews) writes: > >Your consideration of strcpy()/strncpy() is more than a little > >reminiscent of a man who has in hand a claw hammer and a ball peen > >hammer, and who wishes to know why he can't pull nails with the > >latter. > > Not really. It's more like the question of why the carpentry shop > has a ball peen hammer (used for metal working) and doesn't have > a claw hammer. strncpy is a function evidently designed for use with > fixed-length character buffers, not the null-terminated strings that > are semi-standard in C. That makes one wonder why strncpy is included > with functions that are intended for use with null-terminated strings, > and why there is no "safe" copying function for the latter. Actually, the reason why they are 'null-terminated strings' is because they are variable in length. If you are using strncpy then you want an exact number of characters. If you want n characters then you don't want to get n+1 characters. Besides, in C, nothing is completely safe. I think we should all take responsability for our own strings. :-)