At 12:12 PM 10/25/2005, you wrote:
I think memcpy might do what you want. It is supposed to handle
overlapping memory.
Something like:
int Len = strlen(string);
memcpy(&string[Len],string,Len);
The problem you are coming across is that the strcat function needs to
know where the end of the string you are copying from is. As you are
adding to the end, it won't ever find it, and your memory will consist of
one huge string.
You actually need to use MemMove (or memmove in standard C), and you need
to copy len+1 bytes -- if you don't, the new string won't be
NUL-terminated, and only memmove/MemMove is safe for overlapping
regions. I'd write
int len = strlen(string);
MemMove(string + len, string, len + 1);
You also need to make sure that string is allocated with enough storage to
hold all the data after the memory copy.
-- Ben Combee, Senior Software Engineer, Palm, Inc.
"Combee on Palm OS" weblog: http://palmos.combee.net/
Developer Forum Archives: http://news.palmos.com/read/all_forums/
--
For information on using the PalmSource Developer Forums, or to unsubscribe,
please see http://www.palmos.com/dev/support/forums/