_strset_s、 _strset_s_l、 _wcsset_s、 _wcsset_s_l、 _mbsset_s、 _mbsset_s_l

設定字串的字元的字元。這些是 _strset、 _strset_l、 _wcsset、 _wcsset_l、 _mbsset、 _mbsset_l 的安全性增強版本,如 安全性功能,則在 CRT 中 中所述。

重要事項重要事項

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

errno_t _strset_s(
   char *str,
   size_t numberOfElements,
   int c 
);
errno_t _strset_s_l(
   char *str,
   size_t numberOfElements,
   int c,
   locale_t locale
);
errno_t _wcsset_s(
   wchar_t *str,
   size_t numberOfElements,
   wchar_t c 
);
errno_t *_wcsset_s_l(
   wchar_t *str,
   size_t numberOfElements,
   wchar_t c,
   locale_t locale
);
errno_t _mbsset_s(
   unsigned char *str,
   size_t numberOfElements,
   unsigned int c 
);
errno_t _mbsset_s_l(
   unsigned char *str,
   size_t numberOfElements,
   unsigned int c,
   _locale_t locale
);

參數

  • str
    要設定的 NULL 結尾字串。

  • numberOfElements
    str 緩衝區的大小。

  • c
    字元設定。

  • locale
    使用的地區設定。

傳回值

零,如果成功則為,否則為錯誤碼。

這些函式會驗證其引數。如果 str 為 null 指標,則 numberOfElements 引數小於或等於 0,或者傳遞的區塊不是以 null 終止,則無效的參數叫用處理常式,如 參數驗證中所述。如果執行允許繼續執行,這些函式傳回 EINVAL 並將 errno設為 EINVAL。

備註

_strset_s 函式會將所有字元 str 對 c (轉換為 char),除了結束的 null 字元。_wcsset_s 和 _mbsset_s 是 _strset_s 的寬字元和多位元組字元版本。引數和傳回值的資料型別對應的變更。這三個函式其餘部分的運作相同。

輸出值受地區設定的LC_CTYPE 分類設定所影響。如需詳細資訊,請參閱 setlocale 。這些函式沒有以 _l 後綴的版本在這些地區相依的行為上使用目前的地區設定,而以 _l 後綴版本除了它們會使用傳入的地區設定參數之外運作相同。如需詳細資訊,請參閱地區設定

這些函式的偵錯版本會先填入 0xFD 緩衝區。若要停用此行為,請使用 _CrtSetDebugFillThreshold

泛用文字常式對應

TCHAR.H 常式

未定義 _UNICODE & _MBCS

已定義 _MBCS

已定義 _UNICODE

_tcsset_s

_strset_s

_mbsset_s

_wcsset_s

_tcsset_s_l

_strset_s_l

_mbsset_s_l

_wcsset_s_l

需求

程序

必要的標頭檔

_strset_s

<string.h>

_strset_s_l

<tchar.h>

_wcsset_s

<string.h> 或 <wchar.h>

_wcsset_s_l

<tchar.h>

_mbsset_s, _mbsset_s_l

<mbstring.h>

如需其他相容性資訊,請參閱入門介紹中的 相容性 (Compatibility)

範例

// crt_strset_s.c
#include <string.h>
#include <stdio.h>
#include <stdlib.h>

int main( void )
{
   char string[] = "Fill the string with something.";
   printf( "Before: %s\n", string );
   _strset_s( string, _countof(string), '*' );
   printf( "After:  %s\n", string );
}
  
  

.NET Framework 對等用法

不適用。若要呼叫標準 C 函式,請使用 PInvoke。如需更多的資訊,請參閱 Platform Invoke Examples

請參閱

參考

字串操作 (CRT)

地區設定

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

_mbsnbset _mbsnbset_l

memset wmemset

strcat,wcscat _mbscat

strcmp,wcscmp _mbscmp

strcpy, wcscpy, _mbscpy

_strnset、 _strnset_l、 _wcsnset、 _wcsnset_l、 _mbsnset、 _mbsnset_l