_mbsnbset
Sets the first n bytes of a multibyte character string to a specified character.
unsigned char *_mbsnbset( unsigned char *string, unsigned int c, size_t count );
Parameters
- string
- String to be altered.
- c
- Single-byte or multibyte character setting.
- count
- Number of bytes to be set.
Return Value
_mbsnbset returns a pointer to the altered string.
Remarks
The _mbsnbset function sets, at most, the first count bytes of string to c. If count is greater than the length of string, the length of string is used instead of count. If c is a multibyte character and cannot be set entirely into the last byte specified by count, then the last byte will be padded with a blank character. _mbsnbset does not place a terminating null at the end of string.
_mbsnbset is similar to _mbsnset, except that it sets count bytes rather than count characters of c.
Security Note This API incurs 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 |
|---|---|---|---|
| _tcsnset | _strnset | _mbsnbset | _wcsnset |
Requirements
| Routine | Required header | Compatibility |
|---|---|---|
| _mbsnbset | <mbstring.h> | Win 98, Win Me, Win NT, Win 2000, Win XP |
For additional compatibility information, see Compatibility in the Introduction.
Libraries
All versions of the C run-time libraries.
Example
// crt_mbsnbset.c
#include <mbstring.h>
#include <stdio.h>
int main( void )
{
char string[15] = "This is a test";
/* Set not more than 4 bytes of string to be *'s */
printf( "Before: %s\n", string );
_mbsnbset( string, '*', 4 );
printf( "After: %s\n", string );
}
Output
Before: This is a test After: **** is a test
See Also
String Manipulation Routines | _mbsnbcat | _mbsnset | _mbsset | Run-Time Routines and .NET Framework Equivalents