Multibyte Character Conversion
A multibyte character may occupy more than
one byte in memory. The maximum number of bytes that can be used to
represent a multibyte character is the value of the macro
MB_CUR_MAX
, which is defined in
stdlib.h
. Its value is dependent on the current
locale. In the default locale “C”,
MB_CUR_MAX has the value 1.
Every multibyte character corresponds to exactly one character of
type wchar_t
. The functions for multibyte
character conversion are declared in the header file
stdlib.h.
-
intmblen( const char *s, size_tmax); Determines the length of the multibyte character pointed to by
s. The maximum length of the character is specified bymax. Accordingly,maxmust not exceedMB_CUR_MAX.-
size_twctomb( char *s, wchar_twc); Converts the wide character
wcinto the multibyte representation, and writes the corresponding multibyte character in the array addressed bys.-
size_twcstombs( char *s, const wchar_t *p, size_tn); Converts the first
nwide characters referenced bypinto multibyte characters, and copies the results to thechararray addressed bys.-
size_tmbtowc( wchar_t *p, const char *s, size_tmax); Determines the wide character code corresponding to the multibyte character in
s, whose maximum length is specified bymax, and copies the result to thewchar_tvariable referenced byp.-
size_tmbstowcs( wchar_t *p, const char *s, size_tn); Converts the first
nmultibyte characters ofsinto the wide characters and copies the result ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access