In computing, locale.h is a C programming language header file, used for purposes of localization. The header provides two key functions: localeconv
and setlocale
. The former provides access to the current locale, while the latter allows one to set the current locale. The header also defines the struct lconv
, which stores information about a given locale, including the local preference for the display of numbers and currency.
Criticism
This section needs expansion. You can help by adding to it. |
C standard localization functions are criticized because the localization state is stored globally. This means that in a given program all operations involving a locale can use only one locale at a time. As a result, it is very difficult to implement programs that use more than one locale.[1]
Overview of functions
C localization functions and types are defined in locale.h (clocale header in C++).
struct lconv
- explain formatting monetary and other numeric values.
char* decimal point;
- decimal point for non-monetary values
char* grouping;
- size pf digit groups for non-monetary values
struct lconv* localeconv(void);
char* setlocale(int, const char*);
charthousand sep;
- separator for non-monetary values
char* currency symbol;
- currency symbol
char* int curr symbol;
- international currency symbol
char*mon-decimal point
- decimal point for monetary values
char* mon grouping;
- sizes of digit groups for monetary values
char* mon thousand sep;
- separator for digit groups for monetary values
Example
#include <stdio.h>
#include <stdlib.h>
#include <locale.h>
int main(void)
{/* Locale is set to "C" before this. This call sets it
to the "current locale" by reading environment variables: */
setlocale(LC_ALL, "");
const struct lconv * const currentlocale = localeconv();
printf("In the current locale, the default currency symbol is: %s\n",
currentlocale->currency_symbol);
return EXIT_SUCCESS;}
References
- ^ "The Standard C Locale and the Standard C++ Locales". Rogue Wave Software, Inc. 1996.
Cite error: There are <ref group=infosys>
tags on this page, but the references will not show without a {{reflist|group=infosys}}
template (see the help page).