_strset, _strset_l, _wcsset, _wcsset_l, _mbsset, _mbsset_l

將字串字元設定為字元。 這些函式有更安全的版本可供使用;請參閱 、、 _strset_s_l_wcsset_s_l_wcsset_s_mbsset_s_mbsset_s_l_strset_s

重要

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

語法

char *_strset(
   char *str,
   int c
);
char *_strset_l(
   char *str,
   int c,
   _locale_t locale
);
wchar_t *_wcsset(
   wchar_t *str,
   wchar_t c
);
wchar_t *_wcsset_l(
   wchar_t *str,
   wchar_t c,
   _locale_t locale
);
unsigned char *_mbsset(
   unsigned char *str,
   unsigned int c
);
unsigned char *_mbsset_l(
   unsigned char *str,
   unsigned int c,
   _locale_t locale
);

參數

str
以 Null 終止的待設定字串。

c
字元設定。

locale
要使用的地區設定。

傳回值

傳回變更後字串的指標。

備註

_strset 函式會將所有的 str 字元 (終止的 Null 字元除外) 設成 c,轉換成 char_wcsset_mbsset_l_strset 的寬字元和多位元組字元版本,而引數和傳回值的資料類型會隨之改變。 除此之外,這些函式的行為相同。

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

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

重要

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

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

泛型文字常式對應

TCHAR.H 常式 _UNICODE_MBCS 未定義 _MBCS 定義 _UNICODE 定義
_tcsset _strset _mbsset _wcsset
_tcsset_l _strset_l _mbsset_l _wcsset_l

需求

常式 必要的標頭
_strset <string.h>
_strset_l <tchar.h>
_wcsset <string.h > 或 < wchar.h>
_wcsset_l <tchar.h>
_mbsset, _mbsset_l <mbstring.h>

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

範例

// crt_strset.c
// compile with: /W3

#include <string.h>
#include <stdio.h>

int main( void )
{
   char string[] = "Fill the string with something.";
   printf( "Before: %s\n", string );
   _strset( string, '*' ); // C4996
   // Note: _strset is deprecated; consider using _strset_s instead
   printf( "After:  %s\n", string );
}
Before: Fill the string with something.
After:  *******************************

另請參閱

字串操作
地區設定
多位元組字元序列的解譯
_mbsnbset, _mbsnbset_l
memset, wmemset
strcat, wcscat, _mbscat
strcmp, wcscmp, _mbscmp
strcpy, wcscpy, _mbscpy
_strnset, _strnset_l, _wcsnset, _wcsnset_l, _mbsnset, _mbsnset_l