ILE C/C++ Run-Time Library Functions


wcwidth() -- Determine the Display Width of a Wide Character

Format

#include <wchar.h>
int wcwidth (const wint_t wc);

Language Level: XPG4

Threadsafe: Yes.

Description

The wcwidth() function determines the number of printing positions that a graphic representation of wc occupies on a display device. Each of the printing wide characters occupies its own number of printing positions on a display device. The number is independent of its location on the device.

The value of errno may be set to EINVAL (non-printing wide character).

Note:
This function is not available when LOCALETYPE(*CLD) is specified on the compilation command.

Return Value

The wcwidth() function either returns:

The behavior of the wcwidth() function is affected by the LC_CTYPE category of the current locale. If the program is compiled with a UNICODE LOCALETYPE, the wide character properties are those defined by the LC_UNI_CTYPE category of the current locale.

Example that uses wcwidth()


#include <stdio.h>
#include <wchar.h>
 
int   main(void)
{
    wint_t   wc   =   L'A';
 
    printf("%lc   has   a   width   of   %d\n",   wc,   wcwidth(wc));
    return   0;
 
   /**************************************************************************
    The   output   should   be   similar   to   :
    A   has   a   width   of   1
    **************************************************************************/
 
}

Related Information


[ Top of Page | Previous Page | Next Page | Table of Contents | Index ]