At line 11, you initialise
str2 to be an empty string, i.e. an array with 0 length. I'm not sure that's even legal (it's been a long time since I've had to work with C-style strings).
Then, at line 4, you're trying to copy 10 characters, to an address pointing to memory that hasn't been assigned to store that many characters. You're writing past the end of the array pointed to by
str2, hence corrupting the stack.
You need to make sure that when you copy data to an array - or to memory anywhere - that you've assigned enough memory to store that data.
One approach is to assign a chunk of memory when you create the array on the stack:
1 2 3 4 5
|
const site_t MAX_LEN = 256; // A size you think will be enough for whatever you want to do with it
// ...
char str2[MAX_LEN];
|
and check you're not exceeding that memory whenever you write to it.
A better approach is to dynamically allocate the right amount of memory at the point where you need it, i.e. in your
doThis() function.
However, the best approach is to save yourself the trouble, and reduce the risk of introducing errors, by just using the
std::string class that's supplied by the standard library. Since this is, y'know, a C++ forum.