_strnset、_strnset_l、_wcsnset、_wcsnset_l、_mbsnset、_mbsnset_l_strnset, _strnset_l, _wcsnset, _wcsnset_l, _mbsnset, _mbsnset_l

将字符串的字符初始化为给定字符。Initializes characters of a string to a given character. 这些函数的更安全版本已发布;请参阅 _strnset_s、_strnset_s_l、_wcsnset_s、_wcsnset_s_l、_mbsnset_s、_mbsnset_s_l More secure versions of these functions exist; see _strnset_s, _strnset_s_l, _wcsnset_s, _wcsnset_s_l, _mbsnset_s, _mbsnset_s_l.

重要

_mbsnset_mbsnset_l不能用于在 Windows 运行时中执行的应用程序。_mbsnset and _mbsnset_l cannot be used in applications that execute in the Windows Runtime. 有关详细信息,请参阅通用 Windows 平台应用中不支持的 CRT 函数For more information, see CRT functions not supported in Universal Windows Platform apps.

语法Syntax

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

参数Parameters

strstr
要修改的字符串。String to be altered.

cc
字符设置。Character setting.

countcount
要设置的字符数。Number of characters to be set.

localelocale
要使用的区域设置。Locale to use.

返回值Return Value

返回指向修改后的字符串的指针。Returns a pointer to the altered string.

备注Remarks

_Strnset函数设置,最多的第一个计数字符strc (转换为char).The _strnset function sets, at most, the first count characters of str to c (converted to char). 如果计数大于的长度str的长度str而不是使用计数If count is greater than the length of str, the length of str is used instead of count.

_wcsnset_mbsnset宽字符及多字节字符版本的 _strnset_wcsnset and _mbsnset are wide-character and multibyte-character versions of _strnset. 字符串自变量和返回值 _wcsnset是宽字符字符串; 而的 _mbsnset是多字节字符字符串。The string arguments and return value of _wcsnset are wide-character strings; those of _mbsnset are multibyte-character strings. 否则这三个函数否则具有相同行为。These three functions behave identically otherwise.

_mbsnset验证其参数中; 如果str是 null 指针,则调用无效参数处理程序,如中所述参数验证_mbsnset validates its parameters; if str is a null pointer, the invalid parameter handler is invoked, as described in Parameter Validation . 如果允许执行继续,则 _mbsnset返回NULL和设置errnoEINVALIf execution is allowed to continue, _mbsnset returns NULL and sets errno to EINVAL. _strnset_wcsnset不会验证其参数。_strnset and _wcsnset do not validate their parameters.

输出值受区域设置的 LC_CTYPE 类别设置影响;有关详细信息,请参阅 setlocaleThe output value is affected by the setting of the LC_CTYPE category setting of the locale; see setlocale for more information. 这些不带 _l 后缀的函数版本使用此区域设置相关的行为的当前区域设置;带有 _l 后缀的版本相同,只不过它们使用传递的区域设置参数。The versions of these functions without the _l suffix use the current locale for this locale-dependent behavior; the versions with the _l suffix are identical except that they use the locale parameter passed in instead. 有关详细信息,请参阅 LocaleFor more information, see Locale.

一般文本例程映射Generic-Text Routine Mappings

TCHAR.H 例程TCHAR.H routine 未定义 _UNICODE 和 _MBCS_UNICODE & _MBCS not defined 已定义 _MBCS_MBCS defined 已定义 _UNICODE_UNICODE defined
_tcsnset_tcsnset _strnset_strnset _mbsnbset_mbsnbset _wcsnset_wcsnset
_tcsnset_l_tcsnset_l _strnset_l_strnset_l _mbsnbset_l_mbsnbset_l _wcsnset_l_wcsnset_l

要求Requirements

例程Routine 必需的标头Required header
_strnset_strnset <string.h><string.h>
_strnset_l_strnset_l <tchar.h><tchar.h>
_wcsnset_wcsnset <string.h> 或 <wchar.h><string.h> or <wchar.h>
_wcsnset_l_wcsnset_l <tchar.h><tchar.h>
_mbsnset_mbsnset_l_mbsnset, _mbsnset_l <mbstring.h><mbstring.h>

有关其他兼容性信息,请参阅 兼容性For additional compatibility information, see Compatibility.

示例Example

// 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 );
}
Before: This is a test
After:  **** is a test

请参阅See also

字符串操作String Manipulation
区域设置Locale
多字节字符序列的解释Interpretation of Multibyte-Character Sequences
strcat、wcscat、_mbscatstrcat, wcscat, _mbscat
strcmp、wcscmp、_mbscmpstrcmp, wcscmp, _mbscmp
strcpy、wcscpy、_mbscpystrcpy, wcscpy, _mbscpy
_strset、_strset_l、_wcsset、_wcsset_l、_mbsset、_mbsset_l_strset, _strset_l, _wcsset, _wcsset_l, _mbsset, _mbsset_l