Namespaces
Variants

btowc

From cppreference.net
Definido en el encabezado <wchar.h>
wint_t btowc ( int c ) ;
(desde C95)

Amplía un carácter de un solo byte c (reinterpretado como unsigned char ) a su equivalente de carácter ancho.

La mayoría de las codificaciones de caracteres multibyte utilizan códigos de un solo byte para representar los caracteres del conjunto de caracteres ASCII. Esta función puede utilizarse para convertir dichos caracteres a wchar_t .

Contenidos

Parámetros

c - carácter de un solo byte a ampliar

Valor de retorno

WEOF si c es EOF

representación de carácter ancho de c si ( unsigned char ) c es un carácter de un solo byte válido en el estado de cambio inicial, WEOF en caso contrario.

Ejemplo

#include <stdio.h>
#include <wchar.h>
#include <locale.h>
#include <assert.h>
void try_widen(unsigned char c)
{
    wint_t w = btowc(c);
    if(w != WEOF)
        printf("The single-byte character %#x widens to %#x\n", c, w);
    else
        printf("The single-byte character %#x failed to widen\n", c);
}
int main(void)
{
    char *loc = setlocale(LC_ALL, "lt_LT.iso88594");
    assert(loc);
    printf("In Lithuanian ISO-8859-4 locale:\n");
    try_widen('A');
    try_widen('\xdf'); // German letter ß (U+00df) in ISO-8859-4
    try_widen('\xf9'); // Lithuanian letter ų (U+0173) in ISO-8859-4
    setlocale(LC_ALL, "lt_LT.utf8");
    printf("In Lithuanian UTF-8 locale:\n");
    try_widen('A');
    try_widen('\xdf');
    try_widen('\xf9');
}

Salida posible:

In Lithuanian ISO-8859-4 locale:
The single-byte character 0x41 widens to 0x41
The single-byte character 0xdf widens to 0xdf
The single-byte character 0xf9 widens to 0x173
In Lithuanian UTF-8 locale:
The single-byte character 0x41 widens to 0x41
The single-byte character 0xdf failed to widen
The single-byte character 0xf9 failed to widen

Referencias

  • Estándar C11 (ISO/IEC 9899:2011):
  • 7.29.6.1.1 La función btowc (p: 441)
  • Estándar C99 (ISO/IEC 9899:1999):
  • 7.24.6.1.1 La función btowc (p: 387)

Véase también

(C95)
reduce un carácter ancho a un carácter estrecho de un solo byte, si es posible
(función)