Function name : strrev
Header file : <string.h>
Function prototype : char *strrev(char *str);
Function : Reverse the order of all characters in the string and reorder them
Parameters : char *str is the string to be reversed
Return value : Returns a pointer to the string in reverse order
Note : This function does not generate a new string, but modifies the original string. Therefore, it can only reverse the character array, but not the string pointed to by the string pointer, because the string pointer points to a string constant and the constant cannot be modified.
Program example: Reverse the characters in the string array forward and output the result
#include<string.h>#include<stdio.h>intmain(void){charforward[20]=www.dotcpp.com;printf(Beforestrrev():%sn,forward);strrev(forward);printf (Afterstrrev():%sn,forward);return0;}
Running results:
Beforestrrev():www.dotcpp.comAfterstrrev():moc.ppctod.www