_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 Enhancements in the CRT.
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
);
Parameters
- 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 size 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.
The debug versions of these functions first fill the buffer with 0xFD. To disable this behavior, use _CrtSetDebugFillThreshold.
| 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 | Compatibility |
|---|---|---|
| _strset_s | <string.h> | Windows 95, Windows 98, Windows 98 Second Edition, Windows Millennium Edition, Windows NT 4.0, Windows 2000, Windows XP Home Edition, Windows XP Professional, Windows Server 2003 |
| _strset_s_l | <tchar.h> | Windows 95, Windows 98, Windows 98 Second Edition, Windows Millennium Edition, Windows NT 4.0, Windows 2000, Windows XP Home Edition, Windows XP Professional, Windows Server 2003 |
| _wcsset_s | <string.h> or <wchar.h> | Windows 95, Windows 98, Windows 98 Second Edition, Windows Millennium Edition, Windows NT 4.0, Windows 2000, Windows XP Home Edition, Windows XP Professional, Windows Server 2003 |
| _wcsset_s_l | <tchar.h> | Windows 95, Windows 98, Windows 98 Second Edition, Windows Millennium Edition, Windows NT 4.0, Windows 2000, Windows XP Home Edition, Windows XP Professional, Windows Server 2003 |
| _mbsset_s, _mbsset_s_l | <mbstring.h> | Windows 95, Windows 98, Windows 98 Second Edition, Windows Millennium Edition, Windows NT 4.0, Windows 2000, Windows XP Home Edition, Windows XP Professional, Windows Server 2003 |
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 );
}
Output
Before: Fill the string with something. After: *******************************
Not applicable. To call the standard C function, use PInvoke. For more information, see Platform Invoke Examples.