Format
#include <wchar.h>
int wcwidth (const wint_t wc);
Language Level: XPG4
Threadsafe: Yes.
Locale Sensitive: The behavior of this function might be affected by the LC_CTYPE category of the current locale. The behavior might also be affected by the LC_UNI_CTYPE category of the current locale if LOCALETYPE(*LOCALEUCS2) or LOCALETYPE(*LOCALEUTF) is specified on the compilation command. This function is not available when LOCALETYPE(*CLD) is specified on the compilation command. For more information, see Understanding CCSIDs and Locales.
Wide Character Function: See Wide Characters for more information.
Description
The wcwidth() function determines the number of printing positions that a graphic representation of wc occupies on a display device. Each of the printing wide characters occupies its own number of printing positions on a display device. The number is independent of its location on the device.
The value of errno may be set to EINVAL (non-printing wide character).
Return Value
The wcwidth() function either returns:
Example that uses wcwidth()
#include <stdio.h>
#include <wchar.h>
int main(void)
{
wint_t wc = L'A';
printf("%lc has a width of %d\n", wc, wcwidth(wc));
return 0;
/**************************************************************************
The output should be similar to :
A has a width of 1
**************************************************************************/
}
Related Information