C localization functions
![]() |
C standard library (libc) |
---|
General topics |
Miscellaneous headers |
In computing, C localization functions are a group of functions in the C programming language implementing basic localization routines.[1][2] The functions are used in multilingual programs to adapt to the specific locale. In particular, the way of displaying of numbers and currency can be modified. These settings affect the behaviour of input/output functions in the C Standard Library.
Criticism
![]() | This section needs expansion. You can help by adding to it. (November 2011) |
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.[3]
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
- ^ ISO/IEC 9899:1999 specification (PDF). p. 204, § 7.11 Localization.
- ^ Prata, Stephen (2004). C primer plus. Sams Publishing. Appendix B, Section V: The Standard ANSI C Library with C99 Additions. ISBN 0-672-32696-5.
- ^ "The Standard C Locale and the Standard C++ Locales". Rogue Wave Software, Inc. 1996.
- ^ "local.h". utas.edu.au. infosys. Retrieved 14 September 2011.