locale.h
localeconv
Headerlocale.h
Prototype
struct lconv * localeconv(void);
Description
localeconv returns a pointer to a filled-in struct lconv which
contains information specific to the current country or locale.
struct lconv looks like this:
struct lconv
{
char *decimal_point;
char *thousands_sep;
char *int_curr_symbol;
char *currency_symbol;
char *mon_decimal_point;
char *mon_thousands_sep;
char *negative_sign;
char frac_digits;
char p_cs_precedes;
char p_sep_by_space;
char n_cs_precedes;
char n_sep_by_space;
char n_sign_posn;
char lc[6];
};
The fields are:
-
Field/Description
- decimal_point
- The decimal point character for non-monetary usage.
- thousands_sep
- The separator in non-monetary usage to the left of the decimal point.
- int_curr_symbol
- The international currency symbol used in the locale.
- currency_symbol
- The local currency symbol.
- mon_decimal_point
- The decimal point character for monetary usage.
- mon_thousand_sep
- The separator in monetary usage to the left of the decimal point.
- negative_sign
- A string to indicate a negative monetary quantity.
- frac_digits
- The number of digits to display to the right of the decimal point for a monetary quantity.
- p_cs_precedes
- 1 if currency_symbol is a prefix, 0 if currency_symbol is a suffix for positive monetary quantities.
- p_sep_by_space
- 1 if currency_symbol is separated by a space from a positive monetary quantity, 0 if there is no space.
- n_cs_precedes
- 1 if currency_symbol is a prefix, 0 if currency_symbol is a suffix for a negative monetary quantity.
- n_sep_by_space
- 1 if currency_value is separated by a space from a negative monetary quantity, 0 if there is no space.
- n_sign_posn
- A value that indicates how to position negative_sign for a formatted monetary quantity.
- lc[6]
- The current state of the locale. LC_XXX forms the index of this array. Its values are from _LOCALE enumeration in locale.h.
Return Value
A pointer to a struct lconv. The values contained within the structure should be regarded as read only.
Compatibility
DOS Windows 3.x Phar Lap DOSX Win32
See Also
Example
See setlocale
setlocale
Headerlocale.h
Prototype
char * setlocale(int category, const char * locale);
Description
setlocale changes locale-dependent behavior or checks on its current settings. category can be one of the following predefined constants. Digital Mars C++ supports the minimal ANSI C definition and therefore only the following constants have an effect.
-
Constant/Description
- LC_ALL
- Specifies the locale for all categories
- LC_COLLATE
- Change the locale for the strcoll() and strxfrm() functions
- LC_CTYPE
- Change the locale for the character-handling functions and the multi-byte functions.
- LC_MONETARY
- Change the locale for monetary formatting.
- LC_NUMERIC
- Change the locale for numeric formatting.
- LC_TIME
- Change the locale for the strftime() function.
The following locales are recognized:
-
Locale/Description
- C
- The minimal default locale.
- USA
- Predefined in locale.h as the "native" locale. setlocale(LC_ALL,"") selects this.
It also recognizes Italy, Netherlands, Norway, Switzerland, UK, Japan, Korea, China.
Information about the current locale can be obtained by calling setlocale with a NULL second argument. This will return the current locale for the category selected. Having set the locale, a call to localeconv will obtain a pointer to a filled in struct lconv with the specific locale values. See localeconv for details.
Return Value
A pointer containing the currently selected locale for the category specified. A NULL is returned if the locale specified is not supported.
Compatibility
DOS Windows 3.x Phar Lap DOSX Win32
See Also
Example
/* Example for setlocale */
#include <locale.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
char *countries[] =
{
"USA",
"ITALY",
"NORWAY",
NULL
};
void main ()
{
char *loc,
*currency;
int i;
struct lconv *lcptr;
int money = 100; /* Something to display */
/*
setlocale can be called with a NULL locale to
check on its current setting
*/
loc = setlocale (LC_ALL, NULL);
printf (" The default locale is the \"%s\"
locale\n", loc);
for (i = 0; countries[i]; i++)
{
loc = setlocale (LC_ALL, countries[i]);
lcptr = localeconv ();
currency = malloc
(strlen (lcptr-> currency_symbol) + 1);
strcpy (currency, lcptr-> currency_symbol);
if (loc)
printf (" Monetary figure for %s locale:
%s%d\n", loc, currency, money);
free(currency);
}
}
Output
The default locale is the "C" locale
Monetary figure for USA locale: 00
Monetary figure for Italy locale: L. 100
Monetary figure for Norway locale: kr100











