Format
#include <stdio.h> #include <wchar.h> wint_t btowc(int c);
Language Level: ANSI
Threadsafe: Yes.
Description
The btowc() function converts the single byte value c to the wide-character representation of c. If c does not constitute a valid (one-byte) multibyte character in the initial shift state, the btowc() function returns WEOF.
The behavior of the btowc() function is affected by the LC_CTYPE category of the current locale. This function is not available when LOCALETYPE(*CLD) is specified on the compilation command.
Return Value
The btowc() function returns WEOF if c has the value EOF, or if (unsigned char) c does not constitute a valid (one-byte) multibyte character in the initial shift state. Otherwise, it returns the wide-character representation of that character.
If a conversion error occurs, errno may be set to ECONVERT.
Example that uses btowc()
This example scans various types of data.
#include <stdio.h> #include <stdlib.h> #include <wchar.h> #include <local.h> #define UPPER_LIMIT 0xFF int main(void) { int wc; int ch; if (NULL == setlocale(LC_ALL, "/QSYS.LIB/EN_US.LOCALE")) { printf("Locale could not be loaded\n"); exit(1); } for (ch = 0; ch <= UPPER_LIMIT; ++ch) { wc = btowc(ch); if (wc==WEOF) { printf("%#04x is not a one-byte multibyte character\n", ch); } else { printf("%#04x has wide character representation: %#06x\n", ch, wc); } } wc = btowc(EOF); if (wc==WEOF) { printf("The character is EOF.\n", ch); } else { printf("EOF has wide character representation: %#06x\n", wc); } return 0; } /*********************************************************************** If the locale is bound to SBCS, the output should be similar to: 0000 has wide character representation: 000000 0x01 has wide character representation: 0x0001 ... 0xfe has wide character representation: 0x00fe 0xff has wide character representation: 0x00ff The character is EOF. ************************************************************************/
Related Information
(C) Copyright IBM Corporation 1992, 2006. All Rights Reserved.