Syntax
#include <wchar.h> int wcswidth (const wchar_t *wcs, size_t n);Description
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.
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.
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 ****************************************************************************/ }Related Information