_strset、 _strset_l、 _wcsset、 _wcsset_l、 _mbsset、 _mbsset_l

設定字串的字元的字元。更多這些函式的可用安全版本,請參閱 _strset_s、 _strset_s_l、 _wcsset_s、 _wcsset_s_l、 _mbsset_s、 _mbsset_s_l

重要事項重要事項

_mbsset 和 _mbsset_l 不能用於 Windows 執行階段執行的應用程式。如需詳細資訊,請參閱 CRT 函式不支援使用 /ZW

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 函式會將所有字元 (除了結束的 null 字元) 轉換為 c的 str ,轉換為 char。_wcsset 和 _mbsset_l 都是 _strset寬字元和多位元組字元版本,,且引數和傳回值的資料型別對應的變更。這三個函式其餘部分的運作相同。

_mbsset 會驗證其參數。如果 str 為 null 指標,無效的參數叫用處理常式,如 參數驗證中所述。如果執行允許繼續,_mbsset 會傳回 NULL 和 errno 設為 EINVAL。_strset 和 _wcsset 並不驗證它們的參數。

輸出值受地區設定的 LC_CTYPE 類別設定的設定所影響;請參閱 setlocale _wsetlocale 以取得詳細資訊。這些函式版本相同,不過,沒有 _l 結尾使用目前的地區設定和該排列 _l 結尾使用地區設定參數傳遞的型別。如需詳細資訊,請參閱地區設定

安全性注意事項安全性提示

這些函式可能有弱點的緩衝區滿溢威脅。因為它們可能會導致權限的不確定的攻擊,緩衝區滿溢可以為系統攻擊使用。如需詳細資訊,請參閱 Avoiding Buffer Overruns

泛用文字常式對應

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 );
}
  
  

.NET Framework 對等用法

不適用。若要呼叫標準 C 函式,請使用 PInvoke。如需詳細資訊,請參閱平台叫用範例

請參閱

參考

字串操作 (CRT)

地區設定

多位元組字元序列的轉譯工作

_mbsnbset _mbsnbset_l

memset wmemset

strcat,wcscat _mbscat

strcmp,wcscmp _mbscmp

strcpy, wcscpy, _mbscpy

_strnset、 _strnset_l、 _wcsnset、 _wcsnset_l、 _mbsnset、 _mbsnset_l