HP 9000 User Manual page 145

Computers
Hide thumbs Also See for 9000:
Table of Contents

Advertisement

Messaging: printf/scanf Data Formatting
Messages that contain run-time data will often need to be rearranged for
display in different locales. For example, the following statement displays the
date in C locale format:
printf("'!.d/'!.d/'!.d\n", mo, dy, yr);
and would give the following result:
10/31/91
If this date were displayed in the U.K., the
english
locale, it would need to
appear as:
31/10/91
which could be done with a statement such as:
printf("'!.d/'!.d/'!.d\n", dy, mo, yr);
This solution, however, requires a change to the source program: the order of
the
printf
arguments must be changed.
To provide flexible formatting of data, the
printf(3C)
family of routines
permits a conversion specification of the form '!.n$ to indicate that conversion
should be applied to the nth argument. For the C locale, we can use:
printf("'!.1$d/'!.2$d/'!.3$d\n", mo, dy, yr);
and for the
english
locale, we can use:
printf("'!.2$d/'!.1$d/'!.3$d\n", mo, dy, yr);
This solution leaves the order of the
printf
arguments unchanged. It does
require a change to the format string but the format string can be treated as a
8
message and modified as needed for each locale. So our solution becomes:
printf((catgets(catd,NL_SETN,17, 1'!.1$d/'!.2$d/'!.3$d\n")), mo, dy, yr);
Then, the C locale message catalog would contain:
17 '!.1$d/'!.2$d/y'3$d\n
8-12 Advanced NLS TopiCS

Advertisement

Table of Contents
loading

Table of Contents