Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP Posting-Version: version B 2.10.2 9/18/84; site asgb.UUCP Path: utzoo!watmath!clyde!burl!ulysses!allegra!mit-eddie!think!harvard!seismo!hao!asgb!gupta From: gupta@asgb.UUCP (Yogesh K Gupta) Newsgroups: net.lang.c Subject: Re: C programming hint Message-ID: <729@asgb.UUCP> Date: Mon, 15-Jul-85 15:32:09 EDT Article-I.D.: asgb.729 Posted: Mon Jul 15 15:32:09 1985 Date-Received: Thu, 18-Jul-85 05:43:36 EDT References: <899@teddy.UUCP> Organization: Burroughs Corp. ASG, Boulder Colo. Lines: 24 > 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 > > The trick is to use strncpy in an almost recursive way. > Well, I hope you found this useful. Unfortunately, strncpy uses the "loop" that you are trying to avoid. It also makes a redundant (in this case) check for the null character each time through the loop that should be avoided. -- Yogesh Gupta Advanced Systems Group, {sdcrdcf, sdcsvax}!bmcg!asgb!gupta Burroughs Corp., Boulder, CO. -------------------------------------------------------------------- All opinions contained in this message are my own and do not reflect those of my employer or the plant on my desk.