Mail Archives: djgpp/1999/12/25/19:16:32
In comp.os.msdos.djgpp, bowman wrote:
> Andrew R. Gillett <arganoid AT fatal-design DOT com> 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
- Raw text -