cplusplus.com cplusplus.com
cplusplus.com   C++ : Reference : C Library : cstdlib (stdlib.h) : mbtowc
 
- -
C++
Information
Documentation
Reference
Articles
Sourcecode
Forum
Reference
C Library
IOstream Library
Strings library
STL Containers
STL Algorithms
C Library
cassert (assert.h)
cctype (ctype.h)
cerrno (errno.h)
cfloat (float.h)
climits (limits.h)
clocale (locale.h)
cmath (math.h)
csetjmp (setjmp.h)
csignal (signal.h)
cstdarg (stdarg.h)
cstddef (stddef.h)
cstdio (stdio.h)
cstdlib (stdlib.h)
cstring (string.h)
ctime (time.h)
cstdlib (stdlib.h)
functions:
· abort
· abs
· atexit
· atof
· atoi
· atol
· bsearch
· calloc
· div
· exit
· free
· getenv
· labs
· ldiv
· malloc
· mblen
· mbstowcs
· mbtowc
· qsort
· rand
· realloc
· srand
· strtod
· strtol
· strtoul
· system
· wcstombs
· wctomb
functions (non-standard):
· itoa
macros:
· EXIT_FAILURE
· EXIT_SUCCESS
· MB_CUR_MAX
· NULL
· RAND_MAX
types:
· div_t
· ldiv_t
· size_t

-

mbtowc function
int mbtowc ( wchar_t * pwc, const char * pmb, size_t max );
<cstdlib>

Convert multibyte character to wide character

The wchar_t equivalent of the multibyte character pointed by pmb is determined and stored in the location pointed by pwc. The length in bytes of the multibyte character pointed by pmb is returned.
mbtowc has its own internal shift state, which is altered as necessary only by calls to this function.

Parameters

pwc
Pointer to an object of type wchar_t.
Alternativelly, this argument can be a null pointer, in which case the function does not store the wchar_t translation, but still returns the length in bytes of the multibyte character.
pmb
Pointer to the first byte of a multibyte character.
Alternativelly, this argument can be a null pointer, in which case the function resets its internal shift state to the initial value and returns whether multibyte characters have state-dependent encodings or not.
max
Maximum number of bytes to be checked for character length. No more than MB_CUR_MAX characters are examined in any case.

Return Value

If the argument passed as pmb is not a null pointer, the size in bytes of the character pointed by pmb is returned when it forms a valid multibyte character and is not the terminating null character. If it is the terminating null character, the function returns zero, and in the case they do not form a valid multibyte character, -1 is returned.
If the argument passed as pmb is a null pointer, the function returns a nonzero value if multibyte character encodings are state-dependent, and zero otherwise.

See also

mblen Get length of multibyte character (function)
wctomb Convert wide character to multibyte character (function)
mbstowcs Convert multibyte string to wide-character string (function)
wcstombs Convert wide-character string to multibyte string (function)
© The C++ Resources Network, 2000-2007 - All rights reserved
Spotted an error? - contact us