Retro video games delivered to your door every month!
Click above to get retro games delivered to your door ever month!
X-Hacker.org- Watcom C Library Reference - <u>synopsis:</u> http://www.X-Hacker.org [<<Previous Entry] [^^Up^^] [Next Entry>>] [Menu] [About The Guide]
Synopsis:
    #include <stdlib.h>
    int mbtowc( wchar_t *pwc, const char *s, size_t n );
    #include <mbstring.h>
    int _fmbtowc( wchar_t __far *pwc,
                  const char __far *s,
                  size_t n );

Description:
    The mbtowc function converts a single multibyte character pointed to by
    s into the wide character code that corresponds to that multibyte
    character.  The code for the null character is zero.  If the multibyte
    character is valid and pwc is not a NULL pointer, the code is stored in
    the object pointed to by pwc.  At most n bytes of the array pointed to
    by s will be examined.

    The mbtowc function does not examine more than  MB_CUR_MAX bytes.

    The _fmbtowc function is a data model independent form of the mbtowc
    function that accepts far pointer arguments.  It is most useful in mixed
    memory model applications.

Returns:
    If s is a NULL pointer, the mbtowc function returns zero if multibyte
    character encodings are not state dependent, and non-zero otherwise.  If
    s is not a NULL pointer, the mbtowc function returns:

    Value     Meaning

0
    if s points to the null character

len
    the number of bytes that comprise the multibyte character (if the next n
    or fewer bytes form a valid multibyte character)

-1
    if the next n bytes do not form a valid multibyte character


Example:
    #include <stdio.h>
    #include <stdlib.h>
    #include <mbctype.h>

    void main()
      {
        char    *wc = "string";
        wchar_t wbuffer[10];
        int     i, len;

        _setmbcp( 932 );
        printf( "Character encodings are %sstate dependent\n",
                ( mbtowc( wbuffer, NULL, 0 ) )
                ? "" : "not " );

        len = mbtowc( wbuffer, wc, MB_CUR_MAX );
        wbuffer[len] = '\0';
        printf( "%s(%d)\n", wc, len );
        for( i = 0; i < len; i++ )
            printf( "/%4.4x", wbuffer[i] );
        printf( "\n" );
      }

    produces the following:

    Character encodings are not state dependent
    string(1)
    /0073

Classification:
    mbtowc is ANSI, _fmbtowc is not ANSI

Systems:
     mbtowc - All, Netware

    _fmbtowc - DOS, Windows, Win386, Win32, OS/2 1.x(all), OS/2-32

See Also:
    mblen, wctomb, mbstowcs, wcstombs

See Also:

Online resources provided by: http://www.X-Hacker.org --- NG 2 HTML conversion by Dave Pearson