Export (0) Print
Expand All
div
eof
Expand Minimize
This topic has not yet been rated - Rate this topic

_strset_s, _strset_s_l, _wcsset_s, _wcsset_s_l, _mbsset_s, _mbsset_s_l

Set characters of a string to a character. These are versions of _strset, _strset_l, _wcsset, _wcsset_l, _mbsset, _mbsset_l with security enhancements as described in Security Features in the CRT.

Important note Important

_mbsset_s and _mbsset_s_l cannot be used in applications that execute in the Windows Runtime. For more information, see CRT functions not supported with /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-terminated string to be set.

numberOfElements

The size of the str buffer.

c

Character setting.

locale

Locale to use.

Zero if successful, otherwise an error code.

These functions validate their arguments. If str is a null pointer, or the numberOfElements argument is less than or equal to 0, or the block passed in is not null-terminated, then the invalid parameter handler is invoked, as described in Parameter Validation. If execution is allowed to continue, these functions return EINVAL and set errno to EINVAL.

The _strset_s function sets all the characters of str to c (converted to char), except the terminating null character. _wcsset_s and _mbsset_s are wide-character and multibyte-character versions of _strset_s. The data types of the arguments and return values vary accordingly. These functions behave identically otherwise.

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. For more information, see Locale.

The debug versions of these functions first fill the buffer with 0xFD. To disable this behavior, use _CrtSetDebugFillThreshold.

Generic-Text Routine Mappings

TCHAR.H routine

_UNICODE & _MBCS not defined

_MBCS defined

_UNICODE defined

_tcsset_s

_strset_s

_mbsset_s

_wcsset_s

_tcsset_s_l

_strset_s_l

_mbsset_s_l

_wcsset_s_l

Routine

Required header

_strset_s

<string.h>

_strset_s_l

<tchar.h>

_wcsset_s

<string.h> or <wchar.h>

_wcsset_s_l

<tchar.h>

_mbsset_s , _mbsset_s_l

<mbstring.h>

For additional compatibility information, see Compatibility in the Introduction.

// 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 );
}
Before: Fill the string with something.
After:  *******************************

Not applicable. To call the standard C function, use PInvoke. For more information, see Platform Invoke Examples.

Did you find this helpful?
(1500 characters remaining)
Thank you for your feedback
Show:
© 2014 Microsoft. All rights reserved.