localeconv() - C函式


C庫函式struct lconv *localeconv(void)設定或讀取位置相關的資訊。在這些傳回在一個物件中的lconv結構型別。

宣告

以下是localeconv()函式的宣告。

struct lconv *localeconv(void)

引數

  • NA

返回值

這個函式返回一個指向一個struct lconv目前的語言環境,具有以下結構:

typedef struct {
   char *decimal_yiibai;
   char *thousands_sep;
   char *grouping;	
   char *int_curr_symbol;
   char *currency_symbol;
   char *mon_decimal_yiibai;
   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

例子

下面的例子演示了如何使用localeconv()函式。

#include <locale.h>
#include <stdio.h>

int main ()
{
   struct lconv * lc;

   setlocale(LC_MONETARY, "it_IT");
   lc = localeconv();
   printf("Local Currency Symbol: %s
",lc->currency_symbol);
   printf("International Currency Symbol: %s
",lc->int_curr_symbol);

   setlocale(LC_MONETARY, "en_US");
   lc = localeconv();
   printf("Local Currency Symbol: %s
",lc->currency_symbol);
   printf("International Currency Symbol: %s
",lc->int_curr_symbol);

   setlocale(LC_MONETARY, "en_GB");
   lc = localeconv();
   printf ("Local Currency Symbol: %s
",lc->currency_symbol);
   printf ("International Currency Symbol: %s
",lc->int_curr_symbol);

   printf("Decimal Yiibai = %s
", lc->decimal_yiibai);
   
   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 Yiibai = .