I'm trying to make a Palindrome program, that basically returns whatever you enter, just backwards. For some reason, the cNewArray is not only couting the original array backwards, but also the original array. For example if I enter "Hello" it returns "Hello = olleHHello". I'm very new to referencing pointers and addressing and all that stuff, and I think that might be what's causing it. Can someone help?
#include <iostream>
int Absolute ( int nOrigNum )
{
int nAbsolute = 0;
if ( nOrigNum < 0 )
{
while ( nOrigNum < 0 )
{
nOrigNum++;
nAbsolute++;
}
return nAbsolute;
}
else
{
return nOrigNum;
}
}
int PosSwitch ( int nOrigPos )
{
int nTempPos = nOrigPos - 10;
nTempPos++;
int nNewPos = Absolute ( nTempPos );
return nNewPos;
}
void SwitchPrint ( char *cOrigArray, char *cNewArray )
{
for ( int x = 0; x < 10; x++ )
{
if (!( ( cOrigArray [ x ] >= 65 && cOrigArray [ x ] <= 90 ) || ( cOrigArray [ x ] >= 97 && cOrigArray [ x ] <= 122 ) ))
{
cOrigArray [ x ] = ' ';
}
}
for ( int i = 0; i < 10; i++ )
{
int j = PosSwitch ( i );
if ( ( cOrigArray [ i ] >= 65 && cOrigArray [ i ] <= 90 ) || ( cOrigArray [ i ] >= 97 && cOrigArray [ i ] <= 122 ) )
{
cNewArray [ j ] = cOrigArray [ i ];
}
else
{
cNewArray [ j ] = ' ';
}
}
std::cout << cOrigArray << " = " << cNewArray;
std::cout << "\n" << "\n";
}
int main ( int argc, char** argv )
{
char PalindromeArrayOrig [ 10 ];
std::cout << "Enter a word, 10 letters or less." << "\n";
std::cin >> PalindromeArrayOrig;
char PalindromeArrayNew [ 10 ];
SwitchPrint( PalindromeArrayOrig, PalindromeArrayNew );
return 0;
}