_strrev, _wcsrev, _mbsrev
Reverse characters of a string.
char *_strrev( char *string ); wchar_t *_wcsrev( wchar_t *string ); unsigned char *_mbsrev( unsigned char *string );
Parameter
- string
- Null-terminated string to reverse.
Return Value
Returns a pointer to the altered string. No return value is reserved to indicate an error.
Remarks
The _strrev function reverses the order of the characters in string. The terminating null character remains in place. _wcsrev and _mbsrev are wide-character and multibyte-character versions of _strrev. The arguments and return value of _wcsrev are wide-character strings; those of _mbsrev are multibyte-character strings. For _mbsrev, the order of bytes in each multibyte character in string is not changed. These three functions behave identically otherwise.
Security Note These functions incur a potential threat brought about by a buffer overrun problem. Buffer overrun problems are a frequent method of system attack, resulting in an unwarranted elevation of privilege. For more information, see Avoiding Buffer Overruns.
Generic-Text Routine Mappings
| TCHAR.H routine | _UNICODE & _MBCS not defined | _MBCS defined | _UNICODE defined |
|---|---|---|---|
| _tcsrev | _strrev | _mbsrev | _wcsrev |
Requirements
| Routine | Required header | Compatibility |
|---|---|---|
| _strrev | <string.h> | Win 98, Win Me, Win NT, Win 2000, Win XP |
| _wcsrev | <string.h> or <wchar.h> | Win 98, Win Me, Win NT, Win 2000, Win XP |
| _mbsrev | <mbstring.h> | Win 98, Win Me, Win NT, Win 2000, Win XP |
For additional compatibility information, see Compatibility in the Introduction.
Libraries
All versions of the C run-time libraries.
Example
// crt_strrev.c
/* This program checks a string to see
* whether it is a palindrome: that is, whether
* it reads the same forward and backward.
*/
#include <string.h>
#include <stdio.h>
int main( void )
{
char* string = "Able was I ere I saw Elba";
int result;
/* Reverse string and compare (ignore case): */
result = _stricmp( string, _strrev( _strdup( string ) ) );
if( result == 0 )
printf( "The string \"%s\" is a palindrome\n", string );
else
printf( "The string \"%s\" is not a palindrome\n", string );
}
Output
The string "Able was I ere I saw Elba" is a palindrome
See Also
String Manipulation Routines | strcpy | _strset | Run-Time Routines and .NET Framework Equivalents