Determines the display width of wide character strings.
#include <string.h>
int wcswidth (*Pwcs, n) const wchar_t *Pwcs; size_t n;
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.
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. */ } }
This subroutine is part of Base Operating System (BOS) Runtime.
The wcwidth subroutine.
National Language Support Overview for Programming, Subroutines Overview, Understanding Wide Character Display Column Width Subroutines in AIX Version 4.3 General Programming Concepts: Writing and Debugging Programs.