C 库函数 - localeconv()

描述

C 库函数 struct lconv *localeconv(void) 设置或读取地域化信息。它会返回一个 lconv 结构类型的对象。

声明

下面是 localeconv() 函数的声明。

  1. struct lconv *localeconv(void)

参数

  • NA

返回值

该函数返回一个指向当前区域 struct lconv 的指针,它的结构如下:

  1. typedef struct {
  2. char *decimal_point;
  3. char *thousands_sep;
  4. char *grouping;
  5. char *int_curr_symbol;
  6. char *currency_symbol;
  7. char *mon_decimal_point;
  8. char *mon_thousands_sep;
  9. char *mon_grouping;
  10. char *positive_sign;
  11. char *negative_sign;
  12. char int_frac_digits;
  13. char frac_digits;
  14. char p_cs_precedes;
  15. char p_sep_by_space;
  16. char n_cs_precedes;
  17. char n_sep_by_space;
  18. char p_sign_posn;
  19. char n_sign_posn;
  20. } lconv

实例

下面的实例演示了 localeconv() 函数的用法。

  1. #include <locale.h>
  2. #include <stdio.h>
  3. int main ()
  4. {
  5. struct lconv * lc;
  6. setlocale(LC_MONETARY, "it_IT");
  7. lc = localeconv();
  8. printf("Local Currency Symbol: %s\n",lc->currency_symbol);
  9. printf("International Currency Symbol: %s\n",lc->int_curr_symbol);
  10. setlocale(LC_MONETARY, "en_US");
  11. lc = localeconv();
  12. printf("Local Currency Symbol: %s\n",lc->currency_symbol);
  13. printf("International Currency Symbol: %s\n",lc->int_curr_symbol);
  14. setlocale(LC_MONETARY, "en_GB");
  15. lc = localeconv();
  16. printf ("Local Currency Symbol: %s\n",lc->currency_symbol);
  17. printf ("International Currency Symbol: %s\n",lc->int_curr_symbol);
  18. printf("Decimal Point = %s\n", lc->decimal_point);
  19. return 0;
  20. }

让我们编译并运行上面的程序,这将产生以下结果:

  1. Local Currency Symbol: EUR
  2. International Currency Symbol: EUR
  3. Local Currency Symbol: $
  4. International Currency Symbol: USD
  5. Local Currency Symbol: £
  6. International Currency Symbol: GBP
  7. Decimal Point = .