Need help on creating reverse fuction

Hi,
I have created this function to reverse the character array. However, it doesn't print the array in reverse order.
Can someone please tell me the errors in my code?

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
  #include <iostream>
using namespace std;
void r(char x[]);
int main()
{
    int i=0;
    char x[10]={' '};
    cout<<"Enetered Order\n"<<endl;
    for (i=0;i<10;i++)
    {
        cout<<"Enter a character: ";
        cin>>x[i];
    }
    cout<<"\nReversed Order\n"<<endl;
    r(x);
    for(i=0;i<10;i++)
        {
    cout<<x[i]<<endl;
        }
    return 0;
}
void r(char x[])
{
   int i;
   char o;
   for(i=9;i>-1;i--)
   {
       x[i]=o;
       o=x[i-1];
       x[i-1]=x[i];
   }
}
If I do this:

1
2
    int a;
    int b = a;


What value does b have?

(See lines 25 and 28 in your code.)
I don't know about that!

I have to code this program, so that program may ask me to enter 10 alphabets, and then reverse the order of these alphabets and show up on screen.
I don't know about that!

Both a and b have indeterminate values. The same situation occurs in your code. The order in which you place statements matters. Think the logic through.

In your for loop in r what happens when i is 0?
Here is the link to the program ... You can see the exact program

http://programminglearners0349.blogspot.com/2015/05/reverse-character-array.html
Thank you so much, but it doesn't proceed more than one character. What could be the issue?
I am compiling it on cpp.sh
Can anyone help me with this program please?
Topic archived. No new replies allowed.