C programming hint
Andrew Koenig
ark at alice.UUCP
Fri Jul 12 00:57:56 AEST 1985
> 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
Don't. There is no guarantee that strncpy copies one character at a time.
More information about the Comp.lang.c
mailing list