mbtowc, _mbtowc_l

Convertit le caractère multioctets au caractère élargi correspondant

int mbtowc(
   wchar_t *wchar,
   const char *mbchar,
   size_t count 
);
int _mbtowc_l(
   wchar_t *wchar,
   const char *mbchar,
   size_t count,
   _locale_t locale
);

Paramètres

  • wchar
    Adresse d'un caractère large (type wchar_t).

  • mbchar
    Adresse d'une séquence d'octets (provenant d'un caractère multioctets).

  • count
    Nombre d'octets à vérifier.

  • paramètres régionaux
    Paramètres régionaux à utiliser.

Valeur de retour

Si mbchar n'est pas NULL et si l'objet auquel pointembchar forme un caractère multioctet valide, mbtowc retourne la longueur en octets du caractères multioctets. Si mbchar est NULL ou que l'objet vers lequel il pointe est un caractère NULL de caractères larges (L '\0), la fonction renvoie 0. Si l'objet vers lequel mbchar pointe ne constitue pas un caractère multi-octets valide dans les premiers countcaractères, il retourne -1.

Notes

La fonction mbtowcconvertis count octets ou moins pointés par mbchar, si mbchar n'est pas NULL, en le caractère large correspondant. mbtowc range le caractère large résultant dans wchar, si wchar n'est pas NULL. mbtowc n'examine pas plus que les octets jusqu'à MB_CUR_MAX . mbtowc utilise les paramètres régionaux actuels pour un comportemet dépendant de ces paramètres ; _mbtowc_l est identique à la différence qu'il utilise les paramètres régionaux qui lui sont transmis à la place. Pour plus d'informations, consultez Paramètres régionaux.

Configuration requise

Routine

En-tête requis

mbtowc

<stdlib.h>

_mbtowc_l

<stdlib.h>

Pour plus d'informations sur la compatibilité, consultez Compatibilité dans l'introduction.

Bibliothèques

Toutes les versions des bibliothèques Runtime C.

Exemple

// crt_mbtowc.c
/* Illustrates the behavior of the mbtowc function
 */

#include <stdlib.h>
#include <stdio.h>

int main( void )
{
    int      i;
    char    *pmbc    = (char *)malloc( sizeof( char ) );
    wchar_t  wc      = L'a';
    wchar_t *pwcnull = NULL;
    wchar_t *pwc     = (wchar_t *)malloc( sizeof( wchar_t ) );
    printf( "Convert a wide character to multibyte character:\n" );
    wctomb_s( &i, pmbc, sizeof(char), wc );
    printf( "  Characters converted: %u\n", i );
    printf( "  Multibyte character: %x\n\n", *pmbc );

    printf( "Convert multibyte character back to a wide "
            "character:\n" );
    i = mbtowc( pwc, pmbc, MB_CUR_MAX );
    printf( "  Bytes converted: %u\n", i );
    printf( "  Wide character: %x\n\n", *pwc );
    printf( "Attempt to convert when target is NULL\n" );
    printf( "  returns the length of the multibyte character:\n" );
    i = mbtowc( pwcnull, pmbc, MB_CUR_MAX );
    printf( "  Length of multibyte character: %u\n\n", i );

    printf( "Attempt to convert a NULL pointer to a" );
    printf( " wide character:\n" );
    pmbc = NULL;
    i = mbtowc( pwc, pmbc, MB_CUR_MAX );
    printf( "  Bytes converted: %u\n", i );
}

Sortie

Convert a wide character to multibyte character:
  Characters converted: 1
  Multibyte character: 61

Convert multibyte character back to a wide character:
  Bytes converted: 1
  Wide character: 61

Attempt to convert when target is NULL
  returns the length of the multibyte character:
  Length of multibyte character: 1

Attempt to convert a NULL pointer to a wide character:
  Bytes converted: 0

Équivalent .NET Framework

Non applicable. Pour appeler la fonction C standard, utilisez PInvoke. Pour plus d'informations, consultez Exemples d'appel de plateforme.

Voir aussi

Référence

Conversion de données

MultiByteToWideChar

Paramètres régionaux

Interprétation des séquences de caractères multioctets

_mbclen, mblen, _mblen_l

wcstombs, _wcstombs_l

wctomb, _wctomb_l