wcswidth(3) — Subroutines
NAME
wcswidth − Determines the display width of wide-character strings
LIBRARY
Standard C Library (libc.a)
SYNOPSIS
#include <wchar.h>
int wcswidth(
const wchar_t ∗pwcs,
size_t n);
PARAMETERS
nSpecifies the maximum number of wide characters whose display width is to be determined.
pwcsContains a pointer to the wide-character string.
DESCRIPTION
The wcswidth() function 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 behavior of the wcswidth() function is affected by the LC_CTYPE category. Fewer than the number of wide characters specified by the n parameter are counted if a NULL character is encountered first.
EXAMPLES
The following example finds the display column width of a wide-character string.
#include <wchar.h>
#include <locale.h>
main()
{
wchar_t ∗pwcs;
intretval, 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.
∗/
}
}
RETURN VALUES
The wcswidth() function returns the number of display columns to be occupied by the number of wide characters (up to the terminating null wide character specified by the n parameter (or fewer) in the string pointed to by the pwcs parameter. A value of 0 (zero) is returned if the pwcs parameter is a wide-character NULL pointer or a pointer to a wide-character NULL pointer (that is, pwcs or ∗pwcs is NULL). If the pwcs parameter points to an unusable wide character code, a value of -1 is returned.
RELATED INFORMATION
Functions: wcwidth(3).