www.delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/1997/09/25/05:35:54

Date: Thu, 25 Sep 1997 11:35:25 +0200 (IST)
From: Eli Zaretskii <eliz AT is DOT elta DOT co DOT il>
To: "Art S. Kagel" <kagel AT ns1 DOT bloomberg DOT com>
cc: "Peter J. Farley III" <pjfarley AT dorsai DOT org>, djgpp AT delorie DOT com
Subject: Re: Problem with strncpy (DJGPP in msdos window in win95)
In-Reply-To: <Pine.D-G.3.91.970924144033.7569B-100000@dg1>
Message-ID: <Pine.SUN.3.91.970925113440.22174I-100000@is>
MIME-Version: 1.0

On Wed, 24 Sep 1997, Art S. Kagel wrote:

> Peter's
> recommended code is correct, very standard (I do it that way myself),
> and very efficient (the, perhaps unneccessary assignment is a lot
> cheaper than the test that could eliminate it).

Another simple solution to this problem is to initialize the buffer
with a single '\0' character, then use `strncat' instead of `strncpy'.
A frequently-overlooked feature of `strncat' is that it *always* puts
the terminating null character after the copied characters.

(Maybe I should make this the tip of the week ;-).

- Raw text -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019