Comments added by me:
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
string. Pointer mathmatics. Add
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.