Determines the display width of wide character strings.
Standard C Library (libc.a)
The wcswidth subroutine determines the number of display columns to be occupied by the number of wide characters specified by the N parameter in the string pointed to by the Pwcs parameter. The LC_CTYPE category affects the behavior of the wcswidth subroutine. Fewer than the number of wide characters specified by the N parameter are counted if a null character is encountered first.
| Item | Description | 
|---|---|
| N | Specifies the maximum number of wide characters whose display width is to be determined. | 
| Pwcs | Contains a pointer to the wide character string. | 
The wcswidth subroutine returns the number of display columns to be occupied by the number of wide characters (up to the terminating wide character null) specified by the N parameter (or fewer) in the string pointed to by the Pwcs parameter. A value of zero is returned if the Pwcs parameter is a wide character null pointer or a pointer to a wide character null (that is, Pwcs or *Pwcs is null). If the Pwcs parameter points to an unusable wide character code, -1 is returned.
To find the display column width of a wide character string, use the following:
#include <string.h>
#include <locale.h>
#include <stdlib.h>
 
  main()
{
   wchar_t *pwcs;
   int     retval, n ;
     (void)setlocale(LC_ALL, "");
   /* Let pwcs point to a wide character null terminated 
   ** string. Let n be the number of wide characters whose 
   ** display column width is to be determined.
   */
   retval=  wcswidth( pwcs, n );
   if(retval == -1){
           /* Error handling. Invalid wide character code 
           ** encountered in the wide character string pwcs.
           */
   }
}