_strnset, _strnset_l, _wcsnset, _wcsnset_l, _mbsnset, _mbsnset_l
div
eof
TOC
Collapse the table of content
Expand the table of content
Important This document may not represent best practices for current development, links to downloads and other resources may no longer be valid. Current recommended version can be found here. ArchiveDisclaimer

_strnset, _strnset_l, _wcsnset, _wcsnset_l, _mbsnset, _mbsnset_l 

Initialize characters of a string to a given character. These functions are deprecated because more secure versions exist; see _strnset_s, _strnset_s_l, _wcsnset_s, _wcsnset_s_l, _mbsnset_s, _mbsnset_s_l.


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

str

String to be altered.

c

Character setting.

count

Number of characters to be set.

locale

Locale to use.

Returns a pointer to the altered string.

The _strnset function sets, at most, the first count characters of str to c (converted to char). If count is greater than the length of str, the length of str is used instead of count.

_wcsnset and _mbsnset are wide-character and multibyte-character versions of _strnset. 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 validates its parameters; if str is a null pointer, the invalid parameter handler is invoked, as described in Parameter Validation . If execution is allowed to continue, _mbsnset returns NULL and sets errno to EINVAL. _strnset and _wcsnset do not validate their parameters.

The output value is affected by the setting of the LC_CTYPE category setting of the locale; see setlocale for more information. 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.

Generic-Text Routine Mappings
TCHAR.H routine _UNICODE & _MBCS not defined _MBCS defined _UNICODE defined

_tcsnset

_strnset

_mbsnbset

_wcsnset

_tcsnset_l

_strnset_l

_mbsnbset_l

_wcsnset_l

Routine Required header Compatibility

_strnset

<string.h>

Windows 95, Windows 98, Windows 98 Second Edition, Windows Millennium Edition, Windows NT 4.0, Windows 2000, Windows XP Home Edition, Windows XP Professional, Windows Server 2003

_strnset_l

<tchar.h>

Windows 95, Windows 98, Windows 98 Second Edition, Windows Millennium Edition, Windows NT 4.0, Windows 2000, Windows XP Home Edition, Windows XP Professional, Windows Server 2003

_wcsnset

<string.h> or <wchar.h>

Windows 95, Windows 98, Windows 98 Second Edition, Windows Millennium Edition, Windows NT 4.0, Windows 2000, Windows XP Home Edition, Windows XP Professional, Windows Server 2003

_wcsnset_l

<tchar.h>

Windows 95, Windows 98, Windows 98 Second Edition, Windows Millennium Edition, Windows NT 4.0, Windows 2000, Windows XP Home Edition, Windows XP Professional, Windows Server 2003

_mbsnset, _mbsnset_l

<mbstring.h>

Windows 95, Windows 98, Windows 98 Second Edition, Windows Millennium Edition, Windows NT 4.0, Windows 2000, Windows XP Home Edition, Windows XP Professional, Windows Server 2003

For additional compatibility information, see Compatibility in the Introduction.

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

Output

Before: This is a test
After:  **** is a test
Show:
© 2016 Microsoft