_strrev、 _wcsrev、 _mbsrev、 _mbsrev_l
反轉字串的字元。
重要
_mbsrev 和 _mbsrev_l 不能用於 Windows 執行階段執行的應用程式。如需詳細資訊,請參閱 CRT 函式不支援使用 /ZW。
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 函式會反轉字元順序的 string。 結束的 null 字元就地保留。 _wcsrev 和 _mbsrev 是 _strrev 的寬字元和多位元組字元版本。 _wcsrev 的參數和回傳值是寬字元字串,而 _mbsrev 則是多位元組字元字串。 對於 _mbsrev,在 string 不變更位元組順序在每個多位元組字元的。 這三個函式其餘部分的運作相同。
_mbsrev 會驗證其參數。 如果 string1 或 string2 為 null 指標,無效的參數叫用處理常式,如 參數驗證中所述。 如果執行允許繼續, _mbsrev 會傳回 NULL 和 errno 設為 EINVAL。 _strrev 和 _wcsrev 並不驗證它們的參數。
輸出值受地區設定的 LC_CTYPE 類別設定的設定所影響;請參閱 setlocale _wsetlocale 以取得詳細資訊。 這些函式版本相同,不過,沒有 _l 結尾使用目前的地區設定和該排列_l 結尾使用地區設定參數傳遞的型別。 如需詳細資訊,請參閱地區設定。
![]() |
---|
這些函式可能有弱點的緩衝區滿溢威脅。因為它們可能會導致權限的不確定的攻擊,緩衝區滿溢可以為系統攻擊使用。如需詳細資訊,請參閱 Avoiding Buffer Overruns 。 |
泛用文字常式對應
TCHAR.H 常式 |
未定義 _UNICODE & _MBCS |
已定義 _MBCS |
已定義 _UNICODE |
---|---|---|---|
_tcsrev |
_strrev |
_mbsrev |
_wcsrev |
N/A |
N/A |
_mbsrev_l |
N/A |
需求
程序 |
必要的標頭檔 |
---|---|
_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 );
}
.NET Framework 對等用法
不適用。若要呼叫標準 C 函式,請使用 PInvoke。如需詳細資訊,請參閱平台叫用範例。