C programming hint

G A Moffett gam at amdahl.UUCP
Sun Jul 14 13:38:09 AEST 1985


In article <899 at teddy.UUCP> kps at 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



More information about the Comp.lang.c mailing list