|
VMS Help CRTL, localeconv, Example *Conan The Librarian |
#include <stdlib.h>
#include <stdio.h>
#include <limits.h>
#include <locale.h>
#include <string.h>
/* The following test program will set up the British English */
/* locale, and then extract the International Currency symbol */
/* and the International Fractional Digits fields for this */
/* locale and print them. */
int main()
{
/* Declare variables */
char *return_val;
struct lconv *lconv_ptr;
/* Load a locale */
return_val = (char *) setlocale(LC_ALL, "en_GB.iso8859-1");
/* Did the locale load successfully? */
if (return_val == NULL) {
/* It failed to load the locale */
printf("ERROR : The locale is unknown");
exit(EXIT_FAILURE);
}
/* Get the lconv structure from the locale */
lconv_ptr = (struct lconv *) localeconv();
/* Compare the international currency symbol string with an */
/* empty string. If they are equal, then the international */
/* currency symbol is not defined in the locale. */
if (strcmp(lconv_ptr->int_curr_symbol, "")) {
printf("International Currency Symbol = %s\n",
lconv_ptr->int_curr_symbol);
}
else {
printf("International Currency Symbol =");
printf("[Not available in this locale]\n");
}
/* Compare International Fractional Digits with CHAR_MAX. */
/* If they are equal, then International Fractional Digits */
/* are not defined in this locale. */
if ((unsigned char) (lconv_ptr->int_frac_digits) != CHAR_MAX) {
printf("International Fractional Digits = %d\n",
lconv_ptr->int_frac_digits);
}
else {
printf("International Fractional Digits =");
printf("[Not available in this locale]\n");
}
}
Running the example program produces the following result:
International Currency Symbol = GBP
International Fractional Digits = 2
|
|