From: "Andrew R. Gillett" Newsgroups: comp.os.msdos.djgpp Subject: Re: Converting a string to a char * Date: Sat, 25 Dec 1999 14:55:59 -0000 Organization: www.release-dates.co.uk Lines: 30 Message-ID: References: <840i65$auc$1 AT bob DOT news DOT rcn DOT net> NNTP-Posting-Host: modem-179.lemonpeel-angel.dialup.pol.co.uk X-Trace: newsg2.svr.pol.co.uk 946133778 13867 62.137.38.179 (25 Dec 1999 14:56:18 GMT) NNTP-Posting-Date: 25 Dec 1999 14:56:18 GMT X-Complaints-To: abuse AT theplanet DOT net X-Newsreader: MicroPlanet Gravity v2.20 To: djgpp AT delorie DOT com DJ-Gateway: from newsgroup comp.os.msdos.djgpp Reply-To: djgpp AT delorie DOT com In comp.os.msdos.djgpp, bowman wrote: > Andrew R. Gillett wrote: > > >> *b = *s.c_str(); > > > >Change this to: > > > >strcpy (b, s.c_str()); > > b is a pointer to char. s.c_str() returns a pointer to char. So, > b = s.c_str() would work. I don't know exactly how c_str() works - does the char array created by it continue to exist after the line on which it is called? > Doing a strcpy of some arbitrarily long string to a pointer that was > never initialized will dump core and die, if you are lucky. Good point. Tom, if you want to use strcpy, you should define b as a char array with enough elements so that any string you put into it will fit. You could also do it by checking the length of s, and then reserving some memory for b to point to based on the amount of space the string will take up. -- Andrew Gillett http://argnet.fatal-design.com/ ICQ: See homepage Abducensnerve