michaelkrauklis
Programmer
I'm having a little problem with strings, particularly conversion and manipulation of CString/char*. Now am I correct in assuming that CStrings are NULL terminated? And when you create a char* in the manner of "the string" that is alwo NULL terminated, right? My problem is weird, because it doesn't seem to fail in any special case. Here's my simplified code.
the actual code is a bit more complicated but that's the basic idea. The code works the first time through perfectly, but the second time through and the subsequent times after that I get garbage until I eventually get a memory(out of bounds) exception. Is there something wrong with this code? And am I correct in my assumptions that these strings should be NULL terminated?
Also, if this isn't good is there an easy way to concatonate CStrings?
Thanks! MYenigmaSELF:-9
myenigmaself@yahoo.com
Code:
char *base=(char*)calloc(1,8);
base[0]=NULL;
for(all CStrings){
base=(char*)realloc(base,strlen(base)+CString->getLength()+1);
strcat(base,CString->GetBuffer(0));
strcat(base,",");
}
Also, if this isn't good is there an easy way to concatonate CStrings?
Thanks! MYenigmaSELF:-9
myenigmaself@yahoo.com