From Surf Wiki (app.surf) — the open knowledge base
C localization functions
In computing, C localization functions are a group of functions in the C programming language implementing basic localization routines. 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.
Overview of functions
C localization functions and types are defined in ( header in C++).
| Function | Description | setlocalesetlocale | localeconvlocaleconv |
|---|---|---|---|
| sets and gets the current C locale | |||
| returns numeric and monetary formatting details of the current locale |
Criticism
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.
The functions alter the behavior of printf/scanf/strtod which are often used to write saved data to a file or to other programs. The result is that a saved file in one locale will not be readable in another locale, or not be readable at all due to assumptions such as "numbers end at comma characters". Most large-scale software forces the locale to "C" (or another fixed value) to work around these problems.
Example
#include <locale.h>
#include <stdio.h>
#include <stdlib.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
References
- "ISO/IEC 9899:1999 specification".
- Prata, Stephen. (2004). "C primer plus". Sams Publishing.
- (12 April 2011). "ISO/IEC 9899:201x".
- "locale.h". infosys.
- "openbsd/src".
- (1996). "The Standard C Locale and the Standard C++ Locales". Rogue Wave Software, Inc..
This article was imported from Wikipedia and is available under the Creative Commons Attribution-ShareAlike 4.0 License. Content has been adapted to SurfDoc format. Original contributors can be found on the article history page.
Ask Mako anything about C localization functions — get instant answers, deeper analysis, and related topics.
Research with MakoFree with your Surf account
Create a free account to save articles, ask Mako questions, and organize your research.
Sign up freeThis content may have been generated or modified by AI. CloudSurf Software LLC is not responsible for the accuracy, completeness, or reliability of AI-generated content. Always verify important information from primary sources.
Report