Path: utzoo!utgpu!news-server.csri.toronto.edu!cs.utexas.edu!uunet!stretch.cs.mun.ca!leif!haggas From: haggas@kean.ucs.mun.ca Newsgroups: comp.lang.c Subject: Re: Quick Question - Strings Message-ID: <168599@kean.ucs.mun.ca> Date: 10 Dec 90 16:37:12 GMT References: <12677@milton.u.washington.edu> Organization: Memorial University. St.John's Nfld, Canada Lines: 50 In article <12677@milton.u.washington.edu>, mm@blake.u.washington.edu (Eric Gorr) writes: > Well, here it is for all you C experts: > > In BASIC, you can write the simple, one line instruction: > > TEST = "Hello" > > What I want to know is how to do this in C after the code where I declared the > varables. Please provide some sample code... > > Please Respond through E-mail. > > Thanx for your help.....!! > > ------------------------------------------------------------------------------ > Mystery_Man ! All warfare is based on deception - Sun Tzu > ! Diplomacy is the art of letting someone else have > mm@ ! your war - Danielle Vare' > blake.u.washington.edu! He who knows when he can fight and when he cannot will > ! be victorious - Sun Tzu > IBM - I Bought ! Alway mystify, mislead, and surprise the enemy > Macintosh ! - Stonewall Jackson > ------------------------------------------------------------------------------ > > PS: If it matters, I am programming on a MAC with Lightspeed C..but I don't > think it should.. I won't reply via E mail because ANEWS is cheaper for us. You may define a global or externa string array, that is outside of the function main(), like this: char string[] = "Test"; /* the null char '\0' is automatically appended */ or you may define an automatic variable in the main() function, like this: static char string[] = "Test"; /* viable and seen only in main() */ /* local or automatic variables are */ /* not created until the function is called, static variable are created by the compiler and don't disappear when the funtion ( main() ) terminates. */ or , if your cranky: static char string[] = { 'T', 'e', 's', 't', '\0' }; /* character by character - don't forget the end of string terminator */ A global string array will be visible to all the functions succeeeding it, if it is global; therefore, if you wish your string array to be visible to all functions including main(), it must preceed main() in the global data block. Good luck!