function
<cwchar>

btowc

wint_t btowc (int c);
Convert single byte character to wide character
Returns the wide character representation of the byte value c if (and only if) c is a valid multibyte character with a length of a single byte in the initial state of a multibyte sequence.

Otherwise, it returns WEOF.

Parameters

c
The int promotion of a byte (as in a multibyte sequence).
The value is internally converted to an unsigned char to be interpreted.

Return Value

If c is a valid single-byte character in the initial shift state of a multibyte sequence, the function returns its representation as a wchar_t (type-casted to a value of type wint_t).

If c is EOF, or if c is not a valid single-byte representation, the function returns WEOF.

Example

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
/* btowc example */
#include <wchar.h>

int main()
{
  int i,num;
  const char mbs [] = "btowc example";

  num=0;
  for (i=0; i<sizeof(mbs); ++i)
    if (btowc(mbs[i]) != WEOF) ++num;

  wprintf (L"mbs contains %d single-byte characters.\n",num);

  return 0;
}


Output:
mbs contains 14 single-byte characters.

See also