Reverse string.

I have an idea for reverse string programme, but i don't know how to code it, i hope someone can help teach me and code it. So this is my concept :

declare two array(x[] , y[]) first array contain a string. let the string length is 4(included null), so x[4]. And now is the code for reverse the string, x[4] = y[1] , x[3] = y[2] , x[2] = y [3], x[1] = y[4].

Forgive me if i did lots of grammar mistakes. Thanks!
If the string is 4 characters long, the last character is x[3]. This is because the first position in an array is x[0].

This could easily be done in a for loop.

1
2
for ( int i = 0; i < string_length; ++i )
    y[i] = x[string_length-i-1];
Yay295,

Can i have full programme code? I wan to learn how to initialize the variable too.

Thanks!
char x[] = "Letters";
Thanks buddies!
Topic archived. No new replies allowed.