_strrev, _wcsrev, _mbsrev, _mbsrev_l

反轉字串字元。

重要

在 Windows 執行階段中執行的應用程式中無法使用 _mbsrev_mbsrev_l。 如需詳細資訊,請參閱 CRT functions not supported in Universal Windows Platform apps (通用 Windows 平台應用程式中不支援的 CRT 函式)。

語法

char *_strrev(
   char *str
);
wchar_t *_wcsrev(
   wchar_t *str
);
unsigned char *_mbsrev(
   unsigned char *str
);
unsigned char *_mbsrev_l(
   unsigned char *str,
   _locale_t locale
);

參數

str
以 Null 終止的待反轉字串。

locale
要使用的地區設定。

傳回值

傳回變更後字串的指標。 未保留表示錯誤的傳回值。

備註

_strrev 函式會反轉 str 中的字元順序。 原地保留終止的 Null 字元。 _wcsrev_mbsrev 分別是 _strrev 的寬字元版本和多位元組字元版本。 的引數和傳回值 _wcsrev 是寬字元字串。 的引數和傳回值 _mbsrev 是多位元組字元字串。 針對 _mbsrev ,中每個多位元組字元 str 中的位元組順序不會變更。 除此之外,這三個函式的行為相同。

_mbsrev 會驗證其參數。 string1如果 或 string2 為 Null 指標,則會叫用不正確參數處理常式,如參數驗證 中所述 。 若允許繼續執行,_mbsrev 會傳回 NULL,且 errno 設為 EINVAL_strrev_wcsrev 不會驗證其參數。

輸出值會受到 LC_CTYPE 地區設定之類別設定的影響。 如需詳細資訊,請參閱setlocale。 這些函式的版本均相同,除了沒有 _l 後置字元的函式會使用目前的地區設定,而具有 _l 後置字元的函式會改用傳入的地區設定參數。 如需詳細資訊,請參閱 Locale

重要

這些函式可能容易受到緩衝區滿溢的威脅。 緩衝區滿溢可能被當成系統攻擊方式,因為它們可能導致非預期的提高權限。 如需詳細資訊,請參閱 避免緩衝區滿溢

根據預設,此函式的全域狀態會限定于應用程式。 若要變更此行為,請參閱 CRT 中的全域狀態。

泛型文字常式對應

TCHAR.H 常式 _UNICODE_MBCS 未定義 _MBCS 定義 _UNICODE 定義
_tcsrev _strrev _mbsrev _wcsrev
不適用 不適用 _mbsrev_l 不適用

需求

常式 必要的標頭
_strrev <string.h>
_wcsrev <string.h > 或 < wchar.h>
_mbsrev, _mbsrev_l <mbstring.h>

如需相容性詳細資訊,請參閱相容性

範例

// 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 );
}
The string "Able was I ere I saw Elba" is a palindrome

另請參閱

字串操作
地區設定
多位元組字元序列的解譯
strcpy, wcscpy, _mbscpy
_strset, _strset_l, _wcsset, _wcsset_l, _mbsset, _mbsset_l