Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Reversing array values
Message
From
08/08/2005 16:14:49
 
 
To
All
General information
Forum:
Visual C++
Category:
Coding, syntax & commands
Title:
Reversing array values
Miscellaneous
Thread ID:
01039402
Message ID:
01039402
Views:
59
I am having a problem reversing the values in an array. The program I'm writing asks the user to enter a word, then I call the ReverseArray() function to reverse the values and cout the word backwards. When printing the reversed array to the screen, I get a bunch of odd sequencial characters. This is the syntax for my ReverseArray() function.

=======================================================
void ReverseArray(char Input[], char Reversed[])
{

int i;
int x;
int Index;

// Get the index of the first null character
for(x = 0; x < 50; x++)
{
if(Input[x] == '\0')
{
Index = x;
}
}

// Assign values to new array in reverse
for(i = 0; i < x - 1; ++i)
{
x--;
Reversed[i] = Input[x - i];
}
}

=======================================================
What am I doing wrong? From what I can see, it should work just fine. When outputting 'Reversed' to the screen it shows a sequence of '||' for each character entered.
Next
Reply
Map
View

Click here to load this message in the networking platform