another question-sticking one number onto another
I made this function which is supposed to append integer1 onto the end of integer 2.
I'm sure this is 5x more complicated than it needs to be, but right now optimization is not a priority.
Code:
long combine (long integer1, long integer2)
{
long integer3;
// first converts the integers into strings
stringstream ss1;
stringstream ss2;
ss1 << integer1;
ss2 << integer2;
string string1(ss1.str());
string string2(ss2.str());
// then appends string2 onto string1
string1.append(string2);
// converts string1 into an array, one character at a time so that atoi can be used
int x=0;
char array1[string1.length()];
start:
array1[x] = string1[x];
x++;
if (x != string1.length())
goto start;
// uses atoi to convert it back into an integer
integer3 = atoi(array1);
return integer3;
}
The problen is that it does work, but if one of the input numbers is too big (around 7 or 8 digits), it returns a crazy negative number, and I cant find out what is causing it.