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

Routine Required Header Compatibility
_strnset <string.h> Win 95, Win NT
_wcsnset <string.h> or <wchar.h> Win 95, Win NT
_mbsnset <mbstring.h> Win 95, Win NT

For additional compatibility information, see Compatibility in the Introduction.

Libraries

LIBC.LIB Single thread static library, retail version
LIBCMT.LIB Multithread static library, retail version
MSVCRT.LIB Import library for MSVCRT.DLL, retail version

Return Value

Each of these functions returns a pointer to the altered string.

Parameters

string

String to be altered

c

Character setting

count

Number of characters to be set

Remarks

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

Example

/* STRNSET.C */

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

void 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 );
}

Output

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

String Manipulation Routines

See Also   strcat, strcmp, strcpy, _strset