Name | Description | Notes | Source | Availability | |||||||
---|---|---|---|---|---|---|---|---|---|---|---|
LC_ |
All locale categories | M | <locale.h> |
C89 | C90 | C95 | C99 | C11 | |||
LC_ |
Locale category: string collation | M | <locale.h> |
C89 | C90 | C95 | C99 | C11 | |||
LC_ |
Locale category: character encoding and classification | M | <locale.h> |
C89 | C90 | C95 | C99 | C11 | |||
LC_ |
Locale category: monetary | M | <locale.h> |
C89 | C90 | C95 | C99 | C11 | |||
LC_ |
Locale category: numerals | M | <locale.h> |
C89 | C90 | C95 | C99 | C11 | |||
LC_ |
Locale category: representation of time | M | <locale.h> |
C89 | C90 | C95 | C99 | C11 | |||
localeconv() |
Obtain textual locale information | (·) | <locale.h> |
C89 | C90 | C95 | C99 | C11 | |||
NULL |
Null pointer constant | L | M | Headers | C89 | C90 | C95 | C99 | C11 | ||
setlocale() |
Set/get locale information | (·) | <locale.h> |
C89 | C90 | C95 | C99 | C11 | |||
struct lconv |
Description of local notations | T | <locale.h> |
C89 | C90 | C95 | C99 | C11 |
A running C program has the concept of a current locale, a set of representational customs and configuration. This configuration is divided into distinct locale categories. Each category affects different functions, and can be independently set to different locales. Locales are identified by implementation-defined strings. Categories are identified by symbolic constants.
#include <locale.h>
char *setlocale(int cat, const char *loc);
setlocale
can be used to set or get the current locale for a given
category. If loc
is NULL
, it returns a pointer to a
null-terminated string that describes the current locale in
the category cat
.
Otherise, loc
must point to a
null-terminated string that identifies a locale. cat
can then be either LC_
,
indicating that all categories shall be set to the specified
locale, or one of the category symbols beginning with
LC_
below. The function attempts to
set the locale for the category, and returns NULL
on failure. If it
succeeds, it returns a null-terminated string which can
passed as loc
to a future call to
setlocale
in the same category. restoring the locale to previous state.
The result should be saved separately, as other calls to
setlocale
could overwrite it.
Two locale identifiers are defined. A string "C"
identifies a minimal but very portable locale,
and applies by default. [Therefore, it has
to be compatible with the translation-time locale, right?
Otherwise, no string literal containing non-basic characters
would make sense.] An empty string ""
identifies an environment-defined locale, which
often means that values of certain environmental
parameters will be used to determine the locale, although
the mechanism is implementation-defined.
There are five standard locale categories:
Macros with names matching ^LC_[A-Z]
might be added to <locale.h>
.
#include <locale.h>
struct lconv *localeconv(void);
<locale.h>
defines a structure
type struct lconv
, and
localeconv
returns a pointer to such a structure based on the locale
categories LC_
and LC_
.
The structure has the following members:
Member | Type | Meaning | |||
---|---|---|---|---|---|
decimal_point |
char
* |
The string used for a decimal point | in non-monetary quantities | ||
mon_decimal_point |
char
* |
in monetary quantities | |||
thousands_sep |
char
* |
The string used to separate groups of digits | in non-monetary quantities | ||
mon_thousands_sep |
char
* |
in monetary quantities | |||
grouping |
char
* |
Each character is the size of a group of digits [starting from least significant non-fractional digit?] | CHAR_ ⇒ No
further grouping0 ⇒ Previous element is to be
repeatedly used for remaining digitsOther values ⇒ The number of digits that compose the current group |
in non-monetary quantities | |
mon_grouping |
char
* |
in monetary quantities | |||
positive_sign |
char
* |
Sign string | for positive values | in monetary quantities | |
negative_sign |
char
* |
for negative values | |||
currency_symbol |
char
* |
Currency symbol | in local monetary quantities | ||
int_curr_symbol |
char
* |
in international monetary quantities; three letters
according to ISO 4217, plus a separator used as the
space character in int_p_sep_by_space and int_n_sep_by_space |
|||
frac_digits |
char |
Number of fractional digits | in local monetary quantities | ||
int_frac_digits |
char |
in international monetary quantities | |||
p_cs_precedes |
char |
Relation of currency symbol to value | 0 ⇒ symbol precedes value 1 ⇒ symbol succeeds value |
for positive values | in local monetary quantities |
n_cs_precedes |
char |
for negative values | |||
int_p_cs_precedes |
char |
for positive values | in international monetary quantities | ||
int_n_cs_precedes |
char |
for negative values | |||
p_sep_by_space |
char |
Indicator of space separation | 0 ⇒ No space separates the currency
symbol and value 1 ⇒ If currency symbol and sign string are adjacent, a space separates them from the value; otherwise, a space separates the currency symbol from the value 2 ⇒ If currency symbol and sign string are adjacent, a space separates them; otherwise, a space separates the sign string from the value |
for positive values | in local monetary quantities |
n_sep_by_space |
char |
for negative values | |||
int_p_sep_by_space |
char |
for positive values | in international monetary quantities;
space is fourth character in int_curr_symbol |
||
int_n_sep_by_space |
char |
for negative values | |||
p_sign_posn |
char |
Position of sign string | 0 ⇒ Parentheses surround the quantity and
currency symbol 1 ⇒ The sign string precedes the quantity and currency symbol 2 ⇒ The sign string succeeds the quantity and currency symbol 3 ⇒ The sign string immediately precedes the currency symbol 4 ⇒ The sign string immediately succeeds the currency symbol |
for positive values | in local monetary quantities |
n_sign_posn |
char |
for negative values | |||
int_p_sign_posn |
char |
for positive values | in international monetary quantities | ||
int_n_sign_posn |
char |
for negative values |