[C language library function source code]
[This program is compiled in Dev C ++ 4.9.9.2]
/*
Reverses the order of Characters in the string.
The terminating null character remains in place.
Reverses the order of all characters in a string (excluding null characters ).
Returns the string pointer pointing to the reverse order.
*/
Char * my_strrev (char * Str)
{
Char * Right = STR;
Char * Left = STR;
Char ch;
While (* right) Right ++;
Right --;
While (left <right)
{
Ch = * left;
* Left ++ = * right;
* Right -- = CH;
}
Return (STR );
}
/*
The code I write myself is a little ambiguous and not concise,
Not so refreshing. It is worth thinking about this question.
Below is my spam code
*/
Char * my_strreverse (char * Ch)
{
Char tempch, * tch;
Int Len, I;
Tch = CH;
Len = strlen (CH );
For (I = 0; I <Len/2; I ++)
{
Tempch = * tch;
* Tch = * (TCH + len-2 * I-1 );
* (TCH + Len-2 * i-1) = tempch;
Tch ++;
}
Return ch;
}
Int main ()
{
Char STR [] = "ammana_babi ";
Puts (my_strrev (STR ));
Puts (my_strreverse (STR ));
System ("pause ");
Return 0;
}