wctob() — Convert Wide Character to Byte

Format

#include <stdio.h>
#include <wchar.h>
int wctob(wint_t wc);

Language Level

ANSI

Threadsafe

Yes

Locale Sensitive

The behavior of this function might be affected by the LC_CTYPE category of the current locale. The behavior might also be affected by the LC_UNI_CTYPE category of the current locale if LOCALETYPE(*LOCALEUCS2) or LOCALETYPE(*LOCALEUTF) is specified on the compilation command. This function is not available when LOCALETYPE(*CLD) is specified on the compilation command. For more information, see Understanding CCSIDs and Locales.

Wide Character Function

See Wide Characters for more information.

Description

The wctob() function determines whether wc corresponds to a member of the extended character set, whose multibyte character has a length of 1 byte when in the initial shift state.

Return Value

If c corresponds to a multibyte character with a length of 1 byte, the wctob() function returns the single-byte representation. Otherwise, it returns EOF.

If a conversion error occurs, errno may be set to ECONVERT.

Example

This example uses the wctob() function to test if the wide character A is a valid single-byte character.
#include <stdio.h>
#include <wchar.h>
 
int main(void)
{
   wint_t wc = L'A';
 
   if (wctob(wc) == wc)
      printf("%lc is a valid single byte character\n", wc);
   else
      printf("%lc is not a valid single byte character\n", wc);
   return 0;
}
 
   /************************************************************
      The output should be similar to:
 
      A is a valid single byte character
   ************************************************************/

Related Information