_strset, _wcsset, _mbsset
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

_strset, _wcsset, _mbsset

Set characters of a string to a character.

char *_strset(
   char *string,
   int c 
wchar_t *_wcsset(
   wchar_t *string,
   wchar_t c 
unsigned char *_mbsset(
   unsigned char *string,
   unsigned int c 


Null-terminated string to be set.
Character setting.

Return Value

Returns a pointer to the altered string. No return value is reserved to indicate an error.


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

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
_tcsset _strset _mbsset _wcsset


Routine Required header Compatibility
_strset <string.h> Win 98, Win Me, Win NT, Win 2000, Win XP
_wcsset <string.h> or <wchar.h> Win 98, Win Me, Win NT, Win 2000, Win XP
_mbsset <mbstring.h> Win 98, Win Me, Win NT, Win 2000, Win XP

For additional compatibility information, see Compatibility in the Introduction.


All versions of the C run-time libraries.


// crt_strset.c

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

int main( void )
   char string[] = "Fill the string with something";
   printf( "Before: %s\n", string );
   _strset( string, '*' );
   printf( "After:  %s\n", string );


Before: Fill the string with something
After:  ******************************

See Also

String Manipulation Routines | _mbsnbset | memset | strcat | strcmp | strcpy | _strnset | Run-Time Routines and .NET Framework Equivalents

© 2016 Microsoft