Namespaces
Variants

wctob

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

Reduce un carácter ancho c si su equivalente de carácter multibyte en el estado de desplazamiento inicial es un solo byte.

Esto es típicamente posible para los caracteres del conjunto de caracteres ASCII, ya que la mayoría de codificaciones multibyte (como UTF-8) utilizan bytes individuales para codificar esos caracteres.

Contenidos

Parámetros

c - carácter ancho a estrecho

Valor de retorno

EOF si c no representa un carácter multibyte con longitud 1 en estado de desplazamiento inicial.

de lo contrario, la representación de un solo byte de c como unsigned char convertida a int

Ejemplo

#include <locale.h>
#include <wchar.h>
#include <stdio.h>
#include <assert.h>
void try_narrowing(wchar_t c)
{
    int cn = wctob(c);
    if(cn != EOF)
        printf("%#x narrowed to %#x\n", c, cn);
    else
        printf("%#x could not be narrowed\n", c);
}
int main(void)
{
    char* utf_locale_present = setlocale(LC_ALL, "th_TH.utf8");
    assert(utf_locale_present);
    puts("In Thai UTF-8 locale:");
    try_narrowing(L'a');
    try_narrowing(L'๛');
    char* tis_locale_present = setlocale(LC_ALL, "th_TH.tis620");
    assert(tis_locale_present);
    puts("In Thai TIS-620 locale:");
    try_narrowing(L'a');
    try_narrowing(L'๛');
}

Salida posible:

In Thai UTF-8 locale:
0x61 narrowed to 0x61
0xe5b could not be narrowed
In Thai TIS-620 locale:
0x61 narrowed to 0x61
0xe5b narrowed to 0xfb

Referencias

  • Estándar C11 (ISO/IEC 9899:2011):
  • 7.29.6.1.2 La función wctob (p: 441)
  • Estándar C99 (ISO/IEC 9899:1999):
  • 7.24.6.1.2 La función wctob (p: 387)

Véase también

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