Format
#include <wchar.h> int wcswidth (const wchar_t *wcs, size_t n);
Language Level: XPG4
wcswidth determines the number of printing positions occupied on
a display device by a graphic representation of n wide
characters in the string pointed to by wcs (or fewer
than n wide characters, if a null wide character is
encountered before n characters have been exhausted).
The number is independent of its location on the device.
The behavior of wcswidth is affected by the LC_CTYPE category.
Return Value
wcswidth returns the number of printing positions
occupied by the wide-character string. If wcs points
to a null wide character, wcswidth returns 0. If any wide
character in wcs is not a printing character, wcswidth
returns -1.
Note: Under this product, the printing width is 0 for a null character, 1 for each single-byte character, and 2 for each double-byte character.
Example
This example uses wcswidth to calculate the display
width of ABC.
#include <stdio.h> #include <wchar.h>
int main(void)
{
wchar_t *wcs = L"ABC";
printf("wcs has a width of: %d\n", wcswidth(wcs,3));
return 0;
/***************************************************
The output should be similar to:
wcs has a width of: 3 ***************************************************/ }
![]()
wcwidth -- Determine Display Width of Wide
Character
<wchar.h>