Header files: #include <string.h>
The Strrev () function resets the string to its prototype:
Char *strrev (char *str);
"Parameter description" STR is the string to reverse.
Strrev () resets the string that Str refers to.
Return value returns a pointer to the inverted string.
Strrev () does not generate a new string, but instead modifies the original string. So it can only reverse the character array, not the string that the string pointer points to, because the string pointer points to a string constant, and the constant cannot be modified.
Function example to see if Strrev () changes the original string.
#include <stdio.h> #include <string.h>int main () { //changed to char *str1 = "ABCXYZ"; The program crashes at run time. char str1[] = "ABCXYZ"; Char *ret1 = Strrev (str1); printf ("The Origin string of str1 is:%s\n", str1); printf ("The reverse string of STR1 is:%s\n", ret1); return 0;}
Operation Result:
The origin string of str1 is:abcxyz
The reverse string of str1 IS:ZYXCBA
C language Strrev () function: string inverse (reverse, reverse)