C programming hint

Brent Rector brent at cadovax.UUCP
Sat Jul 13 05:48:56 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 */
>		   ^^^       ^^^       ^^^
>		    |         |         |
>		destination  source   how many characters to copy 
>

It seems to me that all you have done is to move the loop into the
strncpy function at the cost of additional procedure call.  Also while
I expect the above will generally work I can think of a couple of bizarre
ways to implement strncpy that would cause the above to fail.  In general
I think overlapped moves produce machine dependent results.

-- 
--------------------------------------------------------------
Brent E. Rector - CONTEL CADO, Torrance, CA
{ decvax, hplabs, ihnp4, ucbvax, sdcrdcf }!trwrb!cadovax!brent
   { onecom, philabs, scgvaxd, ttidca, ucla-cs }!cadovax!brent
				 cadovax!brent at ucla-locus.ARPA



More information about the Comp.lang.c mailing list