Path: utzoo!utgpu!news-server.csri.toronto.edu!cs.utexas.edu!yale!cmcl2!kramden.acf.nyu.edu!brnstnd From: brnstnd@kramden.acf.nyu.edu (Dan Bernstein) Newsgroups: comp.lang.c Subject: Re: Initializing arrays of char Message-ID: <9418:Oct503:06:2790@kramden.acf.nyu.edu> Date: 5 Oct 90 03:06:27 GMT References: <1990Oct4.152756.6850@micrognosis.co.uk> <14796@mentor.cc.purdue.edu> Organization: IR Lines: 25 In article <14796@mentor.cc.purdue.edu> edgincd2@mentor.cc.purdue.edu (Chris Edgington *Computer Science Major*) writes: > In article <1990Oct4.152756.6850@micrognosis.co.uk>, nreadwin@micrognosis.co.uk (Neil Readwin) writes: > > char baz[5] = "12345"; [ explanation ] More to the point, an alert reader will notice that you haven't accounted for the NULL. Whether or not that's legal, you should always treat non-string (i.e., non-NULL-terminated) character arrays as real arrays with no relation between consecutive characters. Something like char baz[5] = { '1', '2', '3', '4', '5' }; This expresses your intent much more clearly. > Therefore, to allocate ample space for your string "12345", you need to have > char baz[6]. Only if you really do mean it that way---but from your article you obviously know how many characters to allocate for a NULL-terminated string, so you wouldn't be asking if that were the answer. (For those new to C, the easy way to allocate a string is char baz[] = "12345";.) Am I reading your mind correctly? :-) ---Dan