Date: Sun, 26 Oct 1997 17:04:54 +0200 (IST) From: Eli Zaretskii To: Erik Max Francis cc: djgpp AT delorie DOT com Subject: Re: strncpy question In-Reply-To: <34525ABE.54074B5A@alcyone.com> Message-ID: MIME-Version: 1.0 Content-Type: TEXT/PLAIN; charset=US-ASCII Precedence: bulk On Sat, 25 Oct 1997, Erik Max Francis wrote: > Basically, don't use strncpy or strncat except in cases where you're > trying to fill a fixed-sized buffer, and do not care whether or not the > result is NUL-terminated (but _do_ care if it is NUL-padded). `strncpy' and `strncat' are not the same in this respect. A frequently-overlooked feature of `strncat' is that it ALWAYS stores a terminating null character. So the following fragment will always produce a null-terminated string: str[0] = '\0'; strncat (str, string1, n1); etc., whereas using `strncpy' requires to append the null by hand. IMHO, initializing the destination is a small price to pay for knowing your strings will always be properly terminated. So I suggest using `strncat' rather than `strncpy'.