How to copy one array into another array backwards

Good evening everyone. I'm in a beginning c++ programming class and we've been given an assignment. I understand that this site doesn't to the programming for me and I'm cool with that. I've research this forum as well as others and I believe that I'm close to a solution, but not quite there.
Task: copy a given array of length 20 into another array of length 20 but in reverse order from the original array. This is a void function.

Here is my code. I'd greatly appreciate any feedback. We haven't learned anything about a library function of copy_backwards or of vectors so this is a very basic program.

void reverse Word(char word [], char reverse [], int howMany)
{
for (int i = howMany -1; i>=0; i--)
for (int j=0; j<howMany; j++)
reverse[j] = word[i];
return;
}

I'm copying only the last letter of the original array so my for loops aren't working.
Thanks for your time.
closed account (48T7M4Gy)
Why have you got 2 loops?

If you imagine two rows of boxes and each row consists of 20 boxes then you are well on the way to seeing why I ask
Last edited on
1
2
3
4
5
6
void reverse Word(char word [], char reverse [], int howMany)
{
for (int i = howMany -1,j=0; i>=0; i--,j++)
reverse[j] = word[i];
return;
}

closed account (48T7M4Gy)
You only need one loop parameter

1
2
3
4
5
6
7
8

void reverseWord(char word [], char reverse [], int howMany)
{
     for (int i = 0; i < howMany; i++)
        reverse[ howMany - i ] = word[ i ];

     return;
}
Last edited on
reverse Word isn't a valid name, use reverse_Word or reverseWord instead
Topic archived. No new replies allowed.