I want to recursively check if two strings are equal, not in size, but character by character. I am unallowed to use loops and the == operator.
I tried to use two parallel arrays, but when testing my function I got undesired results.
Here's what I came up with:
int main()
{
cout << "Checking equivalence of two strings using recursion." << endl << endl;
cout << "For two strings of size 2: ";
char ArrayA[ 100 ] = { 't', 'a', 'r' };
int SizeA = 2;
char ArrayB[ 100 ] = { 't', 'a', 'r' };
int SizeB = 2;
cout << String1EqualString2( ArrayA, SizeA, ArrayB, SizeB );
HoldScreen();
}
bool String1EqualString2( char ArrayA[], int SizeA, char ArrayB[], int SizeB )
{
if ( SizeA <= 1 && SizeB <= 1 )
return true;
else if ( ArrayA[0] != ArrayA[1] && ArrayB[0] != ArrayB[1] )
return false;
return String1EqualString2( ArrayA+1, SizeA-1 , ArrayB+1, SizeB-1 );
}