Reversal of string

Hey guys, I am attempting to take in 2 strings and store them in reverse order in 2 integer arrays. So for example, I enter 12345 into string1 and 54321 would be stored into array1. However, my program hangs after I input my strings. I can't tell what's wrong with my algorithm, is anyone else able to tell me how and where I screwed up?

int reverseStrings(string str1, string str2, int** array1, int** array2)
{

int length1, length2;
length1 = str1.length();
length2 = str2.length();
array1 = new (nothrow)int*[length1];
array2 = new (nothrow)int*[length2];

string::reverse_iterator it1;
string::reverse_iterator it2;

int i = 0;

for (it1=str1.rbegin(); it1<str1.rend(); it1++)
{
*array1[i] = *it1;
i++;
}

i = 0;

for (it2=str2.rbegin(); it2<str1.rend(); it2++)
{
*array2[i] = *it2;
i++;
}

return length1>length2?length1:length2;//Returns the number of digits in whichever integer has more digits

}
You create two int* arrays, but the pointers inside the array still have uninitialized garbage values. I think what you want to do is something like:

 
*array1 = new int[length1];


A suggestion is to make sure there is a 0x0 (NULL terminator) in the input strings. If not your program could be processing the ram address beyond it's boundry because it can't find the 0x0 code.
coerced, we aren't talking about C here.
Topic archived. No new replies allowed.