9.5 Localization (<locale.h>)

The <locale.h> header file declares two functions and one type and defines several macros.

Type

struct lconv


A structure containing members relating to the formatting of numeric values. The structure contains the following members in any order, with values shown in the comments:
char *decimal_point;        /*  "."       */
char *thousands_sep;        /*  ""        */
char *grouping;             /*  ""        */
char *int_curr_symbol;      /*  ""        */
char *currency_symbol;      /*  ""        */
char *mon_decimal_point;    /*  ""        */
char *mon_thousands_sep;    /*  ""        */
char *mon_grouping;         /*  ""        */
char *positive_sign;        /*  ""        */
char *negative_sign;        /*  ""        */
char int_frac_digits;       /*  CHAR_MAX  */
char frac_digits;           /*  CHAR_MAX  */
char p_cs_precedes;         /*  CHAR_MAX  */
char p_sep_by_space;        /*  CHAR_MAX  */
char n_cs_precedes;         /*  CHAR_MAX  */
char n_sep_by_space;        /*  CHAR_MAX  */
char p_sign_posn;           /*  CHAR_MAX  */
char n_sign_posn;           /*  CHAR_MAX  */

These members are described under the localeconv function in this section.

Macros

NULL LC_ALL LC_COLLATE LC_CTYPE LC_MONETARY LC_NUMERIC LC_TIME


Expand to integral constant expressions with distinct values, and can be used as the first argument to the setlocale function.

Functions

char *setlocale(int category, const char *locale);


Selects the appropriate portion of the program's locale as specified by the category and locale arguments. This function can be used to change or query the program's entire current locale or portions thereof.

The following values can be specified for the category argument:


LC_ALL-affects the program's entire locale.

LC_COLLATE-affects the behavior of the strcoll and strxfrm functions.

LC_CTYPE-affects the behavior of the character-handling functions and multibyte functions.

LC_MONETARY-affects the monetary-formatting information returned by the localeconv function.

LC_NUMERIC-affects the decimal-point character for the formatted I/O functions and string-conversion functions, as well as the nonmonetary formatting information returned by the localeconv function.

LC_TIME-affects the behavior of the strftime function.

The following values can be specified for the locale argument:

At program startup, the equivalent of the following is executed:

setlocale(LC_ALL, "C");

The setlocale function returns one of the following:

In either case, the returned pointer to the string is such that a subsequent call with that string value and its associated category will restore that part of the program's locale. This string must not be modified by the program, but it can be overwritten by subsequent calls to setlocale .

struct lconv *localeconv(void);


Sets the components of an object with type struct lconv with values appropriate for formatting numeric quantities according to the rules of the current locale.

The structure members with type char * are pointers to strings, any of which (except decimal_point ) can point to "", which indicates that the value has zero length or is not available in the current locale. Structure members of type char are nonnegative numbers, any of which can be CHAR_MAX to indicate that the value is not available in the current locale. Structure members include the following:


char *decimal_point
The decimal-point character used to format nonmonetary quantities.


char *thousands_sep
The character used to separate groups of digits before the decimal point in formatted nonmonetary quantities.


char *grouping
A string whose elements indicate the size of each group of digits in formatted nonmonetary quantities.


char *int_curr_symbol
The international currency symbol applicable to the current locale. The first three characters contain the alphabetic international currency symbol in accordance with those specified in ISO 4217 Codes for the Representation of Currency and Funds. The fourth character (immediately preceding the null character) is the character used to separate the international currency symbol from the monetary quantity.


char *currency_symbol
The local currency symbol applicable to the current locale.


char *mon_decimal_point
The decimal-point character used to format monetary quantities.


char *mon_thousands_sep
The character used to separate groups of digits before the decimal point in formatted monetary quantities.


char *mon_grouping
A string whose elements indicate the size of each group of digits in formatted monetary quantities.


char *positive_sign
The string used to indicate a nonnegative formatted monetary quantity.


char *negative_sign
The string used to indicate a negative formatted monetary quantity.


char int_frac_digits
The number of fractional digits to be displayed in internationally formatted monetary quantities.


char frac_digits
The number of fractional digits to be displayed in formatted monetary quantities.


char p_cs_precedes
Set to 1 if the currency_symbol precedes the value for a nonnegative formatted monetary quantity; set to 0 if the currency_symbol follows the value.


char p_sep_by_space
Set to 1 if the currency_symbol is separated by a space from the value for a nonnegative formatted monetary quantity; set to 0 if there is no space.


char n_cs_precedes
Set to 1 if the currency_symbol precedes the value for a negative formatted monetary quantity; set to 0 if the currency_symbol follows the value.


char n_sep_by_space
Set to 1 if the currency_symbol is separated by a space from the value for a negative formatted monetary quantity; set to 0 if there is no space.


char p_sign_posn
Set to a value indicating the positioning of the positive_sign for a nonnegative formatted monetary quantity.


char n_sign_posn
Set to a value indicating the positioning of the negative_sign for a negative formatted monetary quantity.

The elements of grouping and mon_ grouping are interpreted according to the following:

The value of p_sign_posn and n_sign_ posn is interpreted as follows:

The localeconv function returns a pointer to the filled in structure. The structure must not be modified by the program, but might be overwritten by subsequent calls to localeconv or to setlocale with categories LC_ALL , LC_MONETARY , or LC_NUMERIC .


Previous Page | Next Page | Table of Contents | Index