Subj : Re: Local character strings To : borland.public.cpp.borlandcpp From : Bob Gonder Date : Thu Sep 22 2005 05:19 pm Ray Sittig wrote: >I thought when a function is called, local variables go on the stack and are >re-initialized on each call. They are. > That doesn't seem to be happening for character >strings as shown in the following short program. Because that is not what you are doing. >void PrintText(int version) >{ >char* MyText[4] = Reserves room on the stack for 4 pointers. > {"2 Line Version: Line 1", Sets the first pointer to point to a literal string stored somewhere in the program. > MyText[0][0] = '1'; Changes the first character of the literal string stored somewhere in the program. You seem to think that >char* MyText[4] = {"2 Line Version: Line 1"}; copies the string, but where would it copy it to? MyText is only pointers. You might try this instead: char MyText[2][32] = {"2 Line Version: Line 1", "2 Line Version: Line 2"}; As now, the strings are copied to the stack. .