Path: utzoo!utgpu!jarvis.csri.toronto.edu!cs.utexas.edu!uwm.edu!zaphod.mps.ohio-state.edu!sunybcs!rutgers!uwvax!umn-d-ub!umn-cs!nis!pwcs!stag!daemon From: john@dynasoft.UUCP (John Stanley) Newsgroups: comp.sys.atari.st Subject: Re: C question Message-ID: <1989Dec18.124934.1487@stag.UUCP> Date: 18 Dec 89 12:49:34 GMT Sender: daemon@stag.UUCP (The devil himself) Organization: Mindtools ST Access Group Lines: 42 [S61304@PRIME-A.POLY-SOUTH-WEST.AC.UK (Rat) writes...] > Why wont Sozobon, Lattice or any other C compiler I've tried compile the > following, from K&R? > > main() > $ > char fred[] = "Some string constant"; > > > > This has been confusing me for a while, as K&R (surely correct!) would > seem to indicate that this is indeed permissible! (Assuming that the '$' character in the line after main() is really suppost to be a '{' character on your machine and just got garbled...??) Can you please tell me where in K&R this example is used? The problem is because you can't assign a string to an unknown size array at runtime (at least not that way)... The array you give there needs to be defined with: static char fred[] = "Some string constant"; Defining the array as static tells the compiler you want the array to be created-and-initialized, as-shown, at compile-time. To assign the array at runtime, you've got a number of options, but the easiest way is: main() { char fred[22]; strcpy(fred, "Some string constant"); } --- John Stanley Software Consultant / Dynasoft Systems