This may not be the case, but I suspect the cause is one of the following:
--Concatenation is including the terminating null character,
--The size isn't being updated after the concatenation (pass the size variables by reference and modify them inside the function)
--The arrays allocated memory is unable to contain all of the concatenated content.
Seeding the rng can be read about here:
http://www.cplusplus.com/reference/clibrary/cstdlib/srand/
--Note: easy way to seed the rng (do this once on each program run)
Below are some tips for C++, which will make things a LOT easier for you. I strongly recommend you become familiar with them, but dont rush too much. Try using the string class for now, and you can play with vectors later, if you bite more than you can chew you'll quickly get sick of programming.
1 2 3 4
|
#include <stdlib.h>
#include <time.h>
// ....
srand ( time(NULL) );
|
Since you are using C++, I strongly recommend using the string class, instead of c-style strings. The string class automatically manages the size, it simplifies usage with the functions given, and (this one is important), it acts as a wrapper. Read about it here:
http://www.cplusplus.com/reference/string/string/
example string declaration: "std::string myString = "Hello World!";"
And, in cases like this, the vector class is also very useful. It acts similar to arrays, but also contains the size, and you dont have a fixed size. Example declarations of a vector:
"std::vector<std::string> myStrings; "
"std::vector<int> myInts; "
Related reading:
http://www.cplusplus.com/reference/stl/vector/
Read these examples and then try to use a vector, it greatly simplifies situations like this.
http://www.cplusplus.com/reference/stl/vector/size/
http://www.cplusplus.com/reference/stl/vector/resize/
http://www.cplusplus.com/reference/stl/vector/operator%5B%5D/
http://www.cplusplus.com/reference/stl/vector/push_back/
http://www.cplusplus.com/reference/stl/vector/pop_back/
I know thats a lot of reading, but it is well worth it. Good luck!