Use C++ instead of C
Since you are using C++, you should really write your code in a C++ way, using std::string
. One of your problems (uninitialized string) can be fixed this way, since it is impossible to define an uninitialized string in C++.
Replace
#include <string.h>
by
#include <string>
Replace
char s[MAX_SIZE1 * MAX_SIZE1 * (MAX_SIZE2 - 1) + 1];
By
std::string s;
Replace
strcat(s, a[hor][i]);
by
s = s + a[hor][i];
If you still want to use C
You have to initialize your output string:
char s[MAX_SIZE1 * MAX_SIZE1 * (MAX_SIZE2 - 1) + 1] = "";
Uninitialized strings typically contain rubbish, and strcat
adds to it, rather than removing it.
In addition, if you want delimiters, you should code that explicitly; strcat
doesn't add any delimiters itself:
strcat(s, ",");