This documentation is archived and is not being maintained.

_strnset, _wcsnset, _mbsnset

Initialize characters of a string to a given format.

char *_strnset(
   char *string,
   int c,
   size_t count 
wchar_t *_wcsnset(
   wchar_t *string,
   wchar_t c,
   size_t count 
unsigned char *_mbsnset(
   unsigned char *string,
   unsigned int c,
   size_t count 


String to be altered.
Character setting.
Number of characters to be set.

Return Value

Returns a pointer to the altered string.


The _strnset function sets, at most, the first count characters of string to c (converted to char). If count is greater than the length of string, the length of string 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.

Generic-Text Routine Mappings

TCHAR.H routine _UNICODE & _MBCS not defined _MBCS defined _UNICODE defined
_tcsnset _strnset _mbsnbset _wcsnset


Routine Required header Compatibility
_strnset <string.h> Win 98, Win Me, Win NT, Win 2000, Win XP
_wcsnset <string.h> or <wchar.h> Win 98, Win Me, Win NT, Win 2000, Win XP
_mbsnset <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_strnset.c

#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 );
   printf( "After:  %s\n", string );


Before: This is a test
After:  **** is a test

See Also

String Manipulation Routines | strcat | strcmp | strcpy | _strset | Run-Time Routines and .NET Framework Equivalents