# reverse function

This is a discussion on reverse function within the C Programming forums, part of the General Programming Boards category; could somebody explain the code below in simple english?errr how what happens and when? i tried drawing diagrams but i ...

1. ## reverse function

could somebody explain the code below in simple english?errr how what happens and when? i tried drawing diagrams but i just confused myself even more. my logic is failing me big time.

thanx a lot

Code:
```void rev( char * str ) {
char temp, *end;
end = str + strlen( str ) -1;

while ( str < end ) {
temp  =  *s;
*str++  =  *end;
*end-- =  temp;
}
}```

2. ## rev again

oops..there was a minor error in the previous code. here it is again!

[code]

void rev( char * str ) {
char temp, *end;
end = str + strlen( str ) -1;

while ( str < end ) {
temp = *str;
*s++ = *end;
*end-- = temp;
}
}
[code]

3. ## revv

oh no...i did it again! sorry!

Code:
```void rev( char * str ) {
char temp, *end;
end = str + strlen( str ) -1;

while ( str < end ) {
temp  =  *str;
*str++  =  *end;
*end-- =  temp;
}
}```

4. ## Re: revv

Code:
```/* take a string 'str', return nothing */
void rev( char * str ) {
/*
Declare 1 character variable, 'tem',
and a pointer to a character 'end'.
*/
char temp, *end;

/*
Point to the last character in the
N-1 to the start of the pointer
and you're at the end, where N
is the length of the string.
*/
end = str + strlen( str ) -1;

/*
while the pointer 'str' is less than
the pointer 'end', do the following
*/
while ( str < end ) {
/*
swap what is currently at each
current pointer 'str' and 'end'
and move each pointer closer
to the other
*/
temp  =  *str;
*str++  =  *end;
*end-- =  temp;
}
}```
Enjoy.

Quzah.

5. ## Re: Re: revv

/*while the pointer 'str' is less than
the pointer 'end', do the following
*/
while ( str < end )
do u mean less in value? please explain. thank you so much.

6. What value? it's a pointer, it holds an memory adress, while the adress of str is smaller than end adress, do the follow.

7. ok i get it now! thanx!