Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP Posting-Version: version B 2.10.2 9/18/84; site rtech.ARPA Path: utzoo!linus!philabs!cmcl2!seismo!hao!hplabs!amdahl!rtech!jeff From: jeff@rtech.ARPA (Jeff Lichtman) Newsgroups: net.lang.c Subject: Re: String help! Message-ID: <236@rtech.ARPA> Date: Thu, 14-Mar-85 02:55:29 EST Article-I.D.: rtech.236 Posted: Thu Mar 14 02:55:29 1985 Date-Received: Mon, 18-Mar-85 03:57:11 EST References: <1156@ukma.UUCP> <113@mit-athena.UUCP> Organization: Relational Technology, Berkeley CA Lines: 35 > Hmmm... According to some of the advice here, the following is not > an acceptable way to declare an initialized array: > > char *fup = "0123456789"; > > The reason is that some C compilers are likely to take the string > constant and put it into a read-only portion of memory. Instead, > if we want an initialized character array, we are supposed to say > something like: > Unnecessarily complicated code here. > > or maybe: > Even more complicated code here. > > John Chambers First of all, it's fine to initialize a character pointer to point to a string constant. Just don't try to alter the constant. If you want to initialize a character pointer to point to a non-constant string, try the following: # define CONST "0123456789" char nonconst[sizeof(CONST)]; char *p = nonconst; strcpy(nonconst, CONST); There, that's not so hard, is it? I don't think it's a good programming practice to modify the value of a constant, anyway. -- Jeff Lichtman at rtech (Relational Technology, Inc.) aka Swazoo Koolak