wcwidth -- Determine Display Width of Wide Character

Format

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

Language Level: XPG4
wcwidth 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 behavior of wcwidth is affected by the LC_CTYPE category of the current locale.

Return Value
wcwidth returns the number of printing positions occupied by wc. If wc is a null wide character, wcwidth returns 0. If wc is not a printing wide character, wc returns -1.

Note: Under this product, the printing width is 0 for a null character, 1 for a single-byte character, and 2 for a double-byte character.

Example
This example determines the printing width for the wide character A.

#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
   **************************************************/
}



wcswidth -- Determine Display Width of Wide-Character String
<wchar.h>