6
Example program using wide characters.. The following program uses wide
characters, and works for both HP-15 and EUC encoding schemes. The
program folds characters strings. A field size is specified defining the WIDTH
for text displayed on the screen. As a given string is printed, any character
whose display would fall outside the designated text region is "folded" onto the
next line.
For instance, if the
WIDTH = 5
and the string is
0123456789,
the result is:
01234
56789
#include <stdio.h>
#include <stdlib.h>
#include <locale.h>
#include <n1_ctype .h>
#define WIDTH 5
#define MAX_MilLTI 100
/* Max number of bytes in
multi-byte array */
#define MAX_VCHAR (MAX_MULTI * (sizeof{vchar_t»)
/* Max number of bytes in
v_char array */
main{argc. argv)
int argcj
char **argvj
{
unsigned char mb_out_array[VIDTH * 2 + l]j / *array for output multi-byte
string */
unsigned char vc_array[sizeof{wchar_t)]j
/* array to hold one wchar */
char *mb_in_ptrj
/* pointer to input multi-byte
array */
vchar_t wc_in_array[MAX_VCHAR]j
/* array for input wchar string */
vchar_t wc_out_array[VIDTH * (sizeof(vchar_t»
+
l]j
vchar_t *in_wc_ptr. *out_vc_ptr. vCi
int counter. screen_sizej
if (!setlocale(LC_ALL. 1111»
{
/* array for output vchar
string */
/* set the locale */
fprintf(stderr."error: cannot set locale\n")i
}
mb_in_ptr
=
argv[l];
counter
=
OJ
in_vc_ptr
=
wc_in_arraYi
/* set pointer to beginning of
multi-byte string */
/* initialize counter to 0 */
/* set pointer to beginning of
input wc array*/
6-20 Developing International Software