Udostępnij za pośrednictwem


_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
);

Parameters

  • str
    Null-terminated string to be set.

  • c
    Character setting.

  • locale
    Locale to use.

Return Value

Returns a pointer to the altered string.

Remarks

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

_tcsset

_strset

_mbsset

_wcsset

_tcsset_l

_strset_l

_mbsset_l

_wcsset_l

Requirements

Routine

Required header

_strset

<string.h>

_strset_l

<tchar.h>

_wcsset

<string.h> or <wchar.h>

_wcsset_l

<tchar.h>

_mbsset, _mbsset_l

<mbstring.h>

For additional compatibility information, see Compatibility in the Introduction.

Example

// 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:  *******************************

.NET Framework Equivalent

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

See Also

Reference

String Manipulation (CRT)

Locale

Interpretation of Multibyte-Character Sequences

_mbsnbset, _mbsnbset_l

memset, wmemset

strcat, wcscat, _mbscat

strcmp, wcscmp, _mbscmp

strcpy, wcscpy, _mbscpy

_strnset, _strnset_l, _wcsnset, _wcsnset_l, _mbsnset, _mbsnset_l