_strnset、 _strnset_l、 _wcsnset、 _wcsnset_l、 _mbsnset、 _mbsnset_l
初始化字串的字元至指定的字元。 這些函式存在更加安全版本中;請參閱 _strnset_s、 _strnset_s_l、 _wcsnset_s、 _wcsnset_s_l、 _mbsnset_s、 _mbsnset_s_l。
重要
_mbsnset 和 _mbsnset_l 不能用於 Windows 執行階段執行的應用程式。如需詳細資訊,請參閱 CRT 函式不支援使用 /ZW。
char *_strnset(
char *str,
int c,
size_t count
);
char *_strnset_l(
char *str,
int c,
size_t count,
locale_t locale
);
wchar_t *_wcsnset(
wchar_t *str,
wchar_t c,
size_t count
);
wchar_t *_wcsnset_l(
wchar_t *str,
wchar_t c,
size_t count,
_locale_t locale
);
unsigned char *_mbsnset(
unsigned char *str,
unsigned int c,
size_t count
);
unsigned char *_mbsnset_l(
unsigned char *str,
unsigned int c,
size_t count,
_locale_t locale
);
參數
str
要修改的字串。c
字元設定。count
要設定的字元數。locale
使用的地區設定。
傳回值
讓指標回到修改的字串。
備註
_strnset函式會,最多, str 第一個 count 字元對 c (轉換為 char)。 如果 count 大於 str的長度,長度 str 而非 count。
_wcsnset 和 _mbsnset都是 _strnset寬字元和多位元組字元版本。 字串引數和傳回值 _wcsnset是寬字元字串;這些 _mbsnset 是多位元組字元字串。 這三個函式其餘部分的運作相同。
_mbsnset驗證其參數;如果 str 為 null 指標,無效的參數叫用處理常式,如 參數驗證 中所述。 如果執行允許繼續, _mbsnset方法會傳回 null 並將 errno設定為無效的 EINVAL。 _strnset 和 _wcsnset 並不驗證它們的參數。
輸出值受地區設定的 LC_CTYPE類別設定的設定所影響;請參閱 setlocale 以取得詳細資訊。 這些函式版本沒有 _l 尾碼此地區設定相關行為使用目前的地區設定;與_l 結尾的版本相同,但使用的地區設定參數。 如需詳細資訊,請參閱地區設定。
泛用文字常式對應
TCHAR.H 常式 |
未定義 _UNICODE & _MBCS |
已定義 _MBCS |
已定義 _UNICODE |
---|---|---|---|
_tcsnset |
_strnset |
_mbsnbset |
_wcsnset |
_tcsnset_l |
_strnset_l |
_mbsnbset_l |
_wcsnset_l |
需求
程序 |
必要的標頭檔 |
---|---|
_strnset |
<string.h> |
_strnset_l |
<tchar.h> |
_wcsnset |
<string.h> 或 <wchar.h> |
_wcsnset_l |
<tchar.h> |
_mbsnset, _mbsnset_l |
<mbstring.h> |
如需其他相容性資訊,請參閱入門介紹中的 相容性 (Compatibility) 。
範例
// crt_strnset.c
// compile with: /W3
#include <string.h>
#include <stdio.h>
int main( void )
{
char string[15] = "This is a test";
/* Set not more than 4 characters of string to be *'s */
printf( "Before: %s\n", string );
_strnset( string, '*', 4 ); // C4996
// Note: _strnset is deprecated; consider using _strnset_s
printf( "After: %s\n", string );
}