Names specified for <locale.h>, “Locales”
Name Description Notes Source Availability
LC_ALL All locale categories M <locale.h> C89 C90 C95 C99 C11
LC_COLLATE Locale category: string collation M <locale.h> C89 C90 C95 C99 C11
LC_CTYPE Locale category: character encoding and classification M <locale.h> C89 C90 C95 C99 C11
LC_MONETARY Locale category: monetary M <locale.h> C89 C90 C95 C99 C11
LC_NUMERIC Locale category: numerals M <locale.h> C89 C90 C95 C99 C11
LC_TIME 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

This header is available in C89, C90, C95, C99 and 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_ALL, 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:

Locale category Meaning Affected functions and objects
LC_COLLATE string collation strcoll, wcscoll, strxfrm and wcsxfrm
LC_TIME textual representation of time strftime and wcsftime
LC_CTYPE multibyte and wide-character encoding btowc, isalnum, isalpha, isgraph, islower, isprint, ispunct, isspace, isupper, iswalnum, iswalpha, iswctype, iswgraph, iswlower, iswprint, iswpunct, iswspace, iswupper, MB_CUR_MAX, mblen, mbrlen, mbrtowc, mbsinit, mbsrtowcs, mbstowcs, mbstowcs_s, mbtowc, tolower, toupper, towctrans, towlower, towupper, wcrtomb, wcsrtombs, wcstombs, wcstombs_s, wctob, wctomb, wctomb_s, wctrans and wctype
LC_NUMERIC non-monetary number formats atof, fprintf, fprintf_s, fscanf, fscanf_s, fwprintf, fwprintf_s, fwscanf, fwscanf_s, localeconv, printf, printf_s, scanf, scanf_s, snprintf, snprintf_s, snwprintf_s, sprintf, sprintf_s, sscanf, sscanf_s, strtod, strtof, strtold, struct lconv, swprintf, swprintf_s, swscanf, swscanf_s, vfprintf, vfprintf_s, vfscanf, vfscanf_s, vfwprintf, vfwprintf_s, vfwscanf, vfwscanf_s, vprintf, vprintf_s, vscanf, vscanf_s, vsnprintf, vsnprintf_s, vsnwprintf_s, vsprintf, vsprintf_s, vsscanf, vsscanf_s, vswprintf, vswprintf_s, vswscanf, vswscanf_s, vwprintf, vwprintf_s, vwscanf, vwscanf_s, wcstod, wcstof, wcstold, wprintf, wprintf_s, wscanf and wscanf_s
LC_MONETARY monetary number formats localeconv

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_NUMERIC and LC_MONETARY. The structure has the following members:

Members of struct lconv
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_MAX ⇒ No further grouping
0 ⇒ Previous element is to be repeatedly used for remaining digits
Other 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

CHaR
Sitemap Supported
Site format updated 2024-06-05T22:37:07.391+0000
Data updated 1970-01-01T00:00:00.000+0000
Page updated 2023-10-04T20:24:03.209+0000