strncpy

Teruhiko Kurosaka - Sun Intercon kuro at vodka.Sun.Com
Sat Jan 6 20:44:31 AEST 1990


In article <11616 at csli.Stanford.EDU> poser at csli.Stanford.EDU (Bill Poser) writes:
 |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.
I have no opinion about philosophical correctness of the current behavior of
strncpy() but always do:
	strncpy(to, from, n);
	to[n]=0; 
This ensures the copied string is always null-terminated, if this is what you 
mean by "safe".
--
-------
T. Kurosaka ("Kuro") --- Sun Microsystems, Intercontinental Operation
Internet:kuro at Corp.Sun.Com Voice:+1(415)496-6121/336-5921 Fax:+1(415)858-0284
Mail: Mail Stop A6-18, 1870 Embarcadero Rd., Palo Alto, CA 94303, USA



More information about the Comp.lang.c mailing list