The setlocale() function is the interface to the program's locale. In general, any program that requires the invocation country's conventions should place a call such as:
#include <locale.h> /early in the program's execution path. This causes the program's current locale to change to the appropriate local version (if possible), since LC_ALL is the macro that specifies the entire locale instead of one category. The following are the standard categories:...
/ setlocale(LC_ALL, "");
| LC_COLLATE | sorting information |
| LC_CTYPE | character classification information |
| LC_MONETARY | currency printing information |
| LC_NUMERIC | numeric printing information |
| LC_TIME | date and time printing information |
| LC_MESSAGES | message language information |
The setlocale() function returns the name of the current locale for a given category (or LC_ALL) and serves in an inquiry-only capacity when its second argument is a null pointer. Thus, code along the lines of the following can be used to change the locale or a portion thereof for a limited duration:
#include <locale.h> /Most programs will never need this capability....
/ char
oloc; /
...
/ oloc = setlocale(LC_cat, NULL); if (setlocale(LC_cat, "new") != 0) { /
use temporarily changed locale
/ (void)setlocale(LC_cat, oloc); }