btowc
|
Défini dans l'en-tête
<wchar.h>
|
||
|
wint_t btowc
(
int
c
)
;
|
(depuis C95) | |
Élargit un caractère mono-octet
c
(réinterprété comme
unsigned
char
) à son équivalent en caractère large.
La plupart des encodages de caractères multioctets utilisent des codes à un octet pour représenter les caractères du jeu de caractères ASCII. Cette fonction peut être utilisée pour convertir ces caractères en wchar_t .
Table des matières |
Paramètres
| c | - | caractère à un octet à élargir |
Valeur de retour
WEOF
si
c
est
EOF
représentation en caractère large de
c
si
(
unsigned
char
)
c
est un caractère mono-octet valide dans l'état de décalage initial,
WEOF
sinon.
Exemple
#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'); }
Sortie possible :
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
Références
- Norme C11 (ISO/CEI 9899:2011) :
-
- 7.29.6.1.1 La fonction btowc (p: 441)
- Norme C99 (ISO/CEI 9899:1999) :
-
- 7.24.6.1.1 La fonction btowc (p: 387)
Voir aussi
|
(C95)
|
rétrécit un caractère large en un caractère étroit d'un seul octet, si possible
(fonction) |
|
Documentation C++
pour
btowc
|
|