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.
Overview of functions
C localization functions and types are defined in locale.h (clocale header in C++).[3]
Function | Description |
---|---|
setlocale
|
sets and gets the current C locale |
localeconv
|
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.[4]
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. FUNCTIONS
TYPES OF FUNCTIONS
1.With No arguments and no return type:
(i) In this type of function ,the function is called without passing any arguments.so the control moves fromcalling function to called function.
(ii) the variables are declared in th function,data is processed in the function and the result is also displayed in the function.Now the control returns from called to calling function.
2.with Arguments and no return type:
In this type of function the function is invoked by passing some arguement
(i) now the control moves from calling function t the called function with these arguements
(ii) if any variables required,declared in the function
(iii) process the data
(iv) display the result in the function
(v) the control returns back to its calling function
(vi) Actual parameters:the parameters present in the function call are call actual parameters.
(vii) Formal parameters:The parameters present in the function definition are called Formal parameters
(viii) The actual and formal parameters should be in:
a. in number and data types
3.With Arguments and return type:
(i) The result is not displayed in the function ,it will send back to the program
(ii) RETURN : By using return statement ,the result is sent back to its calling function
4.Call by reference.
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.
- ^ "locale.h". utas.edu.au. infosys. Retrieved 14 September 2011.
- ^ "The Standard C Locale and the Standard C++ Locales". Rogue Wave Software, Inc. 1996.
See also