_mbsnbset
Remonter à String.h - Index
Header File
mbstring.h
Category
Memory and String Manipulation Routines
Prototype
unsigned char *_mbsnbset(unsigned char str, unsigned int ch, size_t maxlen);
Description
_mbsnbset sets at most maxlen number of bytes in the str string to the ch character. The ch argument can be a single or multibyte character.
The function quits if the terminating null character is found before maxlen is reached. If ch is a multibyte character that cannot be accommodated at the end of str, the last character in str is set to a blank character.
Return Value
_mbsnbset returns a pointer to char, the new string made by given character.
Example
#include <mbstring.h>
/* Creates a new string filled by the given character the
given number of times.
*/
char* fill_string(unsigned int ch, size_t chars)
{
/* Decide over the length of the string (for MBCS it's chars * 2 bytes) */
int str_len = (ch <= 0xff) ? chars : chars * 2;
/* Generate a new string made of the given character */
return _mbsnbset((char*)malloc(str_len + 1), ch, str_len);
}