Standards / Extensions | C or C++ | Dependencies |
---|---|---|
XPG4 |
both |
#include <wchar.h>
int wcswidth(const wchar_t *wcs, size_t n);
Determines the number of printing positions that a graphic representation of n wide characters (or fewer than n wide characters, if a NULL wide character is encountered before n wide characters have been exhausted), in the wide-character string pointed to by wcs, occupies on a display device. The number of printing positions is independent of its location on the device.
If successful, wcswidth() returns the number of printing positions occupied by the wide-character string pointed to by wcs.
If wcs points to a NULL wide character, wcswidth() returns 0.
If any wide character in the wide-character string pointed to by wcs is not a printing wide character, wcswidth() returns -1.
The behavior of wcswidth() is affected by the LC_CTYPE category.
⁄* CELEBW27 *⁄
#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));
}
wcs has a width of: 3