当前位置: 首页 > 文档资料 > C 标准库 中文版 >

struct lconv *localeconv(void)

优质
小牛编辑
133浏览
2023-12-01

描述 (Description)

C库函数struct lconv *localeconv(void)设置或读取位置相关信息。 它们在lconv结构类型的对象中返回。

声明 (Declaration)

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

struct lconv *localeconv(void)

参数 (Parameters)

  • NA

返回值 (Return Value)

此函数返回指向当前语言环境的struct lconv的指针,该struct lconv具有以下结构 -

typedef struct {
   char *decimal_point;
   char *thousands_sep;
   char *grouping;	
   char *int_curr_symbol;
   char *currency_symbol;
   char *mon_decimal_point;
   char *mon_thousands_sep;
   char *mon_grouping;
   char *positive_sign;
   char *negative_sign;
   char int_frac_digits;
   char frac_digits;
   char p_cs_precedes;
   char p_sep_by_space;
   char n_cs_precedes;
   char n_sep_by_space;
   char p_sign_posn;
   char n_sign_posn;
} lconv

例子 (Example)

以下示例显示了localeconv()函数的用法。

#include <locale.h>
#include <stdio.h>
int main () {
   struct lconv * lc;
   setlocale(LC_MONETARY, "it_IT");
   lc = localeconv();
   printf("Local Currency Symbol: %s\n",lc->currency_symbol);
   printf("International Currency Symbol: %s\n",lc->int_curr_symbol);
   setlocale(LC_MONETARY, "en_US");
   lc = localeconv();
   printf("Local Currency Symbol: %s\n",lc->currency_symbol);
   printf("International Currency Symbol: %s\n",lc->int_curr_symbol);
   setlocale(LC_MONETARY, "en_GB");
   lc = localeconv();
   printf ("Local Currency Symbol: %s\n",lc->currency_symbol);
   printf ("International Currency Symbol: %s\n",lc->int_curr_symbol);
   printf("Decimal Point = %s\n", lc->decimal_point);
   return 0;
}

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

Local Currency Symbol: EUR
International Currency Symbol: EUR
Local Currency Symbol: $
International Currency Symbol: USD
Local Currency Symbol: £
International Currency Symbol: GBP
Decimal Point = .