Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP
Posting-Version: version B 2.10.2 9/18/84; site amdahl.UUCP
Path: utzoo!watmath!clyde!burl!ulysses!allegra!mit-eddie!genrad!decvax!decwrl!sun!amdahl!gam
From: gam@amdahl.UUCP (G A Moffett)
Newsgroups: net.lang.c
Subject: Re: C programming hint
Message-ID: <1786@amdahl.UUCP>
Date: Sat, 13-Jul-85 23:38:09 EDT
Article-I.D.: amdahl.1786
Posted: Sat Jul 13 23:38:09 1985
Date-Received: Wed, 17-Jul-85 05:23:20 EDT
References: <899@teddy.UUCP>
Reply-To: gam@amdahl.UUCP (G A Moffett)
Organization: Blue Mouse Trailer Resort, Hellmouth, CA
Lines: 18
Keywords: strncpy, portability
Summary: don't copy overlapping strings with str[n]cpy()

In article <899@teddy.UUCP> kps@teddy.UUCP (Kesavan P. Srinivasan) writes:
>I found a way to initialize an array of characters without using a loop.
>Here is the method I used:
>
>	char blanks[SIZE];	/* declare array of SIZE elements */
>	
>	blanks[0] = ' ';	/* initialize 1st element */
>
>	strncpy(blanks + 1, blanks, SIZE - 1);	/* initialize entire array */

This is machine-dependent so don't expect this to be portable.

Generally speaking, you shouldn't use the string library functions on
overlapping strings.


-- 
Gordon A. Moffett		...!{ihnp4,cbosgd,hplabs}!amdahl!gam