[ Bottom of Page | Previous Page | Next Page | Contents | Index | Library Home | Legal | Search ]

Technical Reference: Base Operating System and Extensions, Volume 2

wcswidth Subroutine

Purpose

Determines the display width of wide character strings.

Library

Standard C Library (libc.a)

Syntax

#include <string.h>


int wcswidth (* Pwcs n)
const wchar_t *Pwcs;
size_t n;

Description

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.

Parameters

N Specifies the maximum number of wide characters whose display width is to be determined.
Pwcs Contains a pointer to the wide character string.

Return Values

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.

Examples

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.
           */
   }
}

Related Information

The wcwidth (wcwidth Subroutine) subroutine.

National Language Support Overview and Wide Character Display Column Width Subroutines in AIX 5L Version 5.2 National Language Support Guide and Reference.

Subroutines, Example Programs, and Libraries in AIX 5L Version 5.2 General Programming Concepts: Writing and Debugging Programs.

[ Top of Page | Previous Page | Next Page | Contents | Index | Library Home | Legal | Search ]