_strset, _strset_l, _wcsset, _wcsset_l, _mbsset, _mbsset_l
Collapse the table of content
Expand the table of content

_strset, _strset_l, _wcsset, _wcsset_l, _mbsset, _mbsset_l

Set characters of a string to a character. More secure versions of these functions are available; see _strset_s, _strset_s_l, _wcsset_s, _wcsset_s_l, _mbsset_s, _mbsset_s_l.

char *_strset(
   char *str,
   int c 
char *_strset_l(
   char *str,
   int c,
   locale_t locale
wchar_t *_wcsset(
   wchar_t *str,
   wchar_t c 
wchar_t *_wcsset_l(
   wchar_t *str,
   wchar_t c,
   locale_t locale
unsigned char *_mbsset(
   unsigned char *str,
   unsigned int c 
unsigned char *_mbsset_l(
   unsigned char *str,
   unsigned int c,
   _locale_t locale


Null-terminated string to be set.


Character setting.


Locale to use.

Returns a pointer to the altered string.

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

_mbsset 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, _mbsset returns NULL and sets errno to EINVAL. _strset and _wcsset 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. For more information, see Locale.

Security Note    These functions incur a potential threat brought about by a buffer overrun problem. Buffer overrun problems are a frequent method of system attack, resulting in an unwarranted elevation of privilege. For more information, see Avoiding Buffer Overruns.

Generic-Text Routine Mappings

TCHAR.H routine

_UNICODE & _MBCS not defined

_MBCS defined

_UNICODE defined










Required header






<string.h> or <wchar.h>



_mbsset, _mbsset_l


For additional compatibility information, see Compatibility in the Introduction.

// crt_strset.c
// compile with: /W3

#include <string.h>
#include <stdio.h>

int main( void )
   char string[] = "Fill the string with something.";
   printf( "Before: %s\n", string );
   _strset( string, '*' ); // C4996
   // Note: _strset is deprecated; consider using _strset_s instead
   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.

Community Additions

© 2015 Microsoft