3
// code
#include <stdio.h>
#include <stdlib.h>
#include <locale.h>

#define SIZE 32
const char name[][SIZE] = {"en_US.utf8", "zh_CN.utf8", "zh_HK.utf8", "zh_TW.big5", "fr_BE.iso88591"};

int main(void)
{
    int count = sizeof(name) / SIZE;
    for (int i = 0; i < count; i++)
    {
        setlocale(LC_ALL, name[i]);
        const struct lconv *p = localeconv();
        printf("locale:[%s], currency symbol: [%s]\n", name[i], p->currency_symbol);
        printf("locale:[%s], international currency symbol: [%s]\n", name[i], p->int_curr_symbol); // why a tail space
    }

    return 0;
}

// output
locale:[en_US.utf8], currency symbol: [$]
locale:[en_US.utf8], international currency symbol: [USD ]
locale:[zh_CN.utf8], currency symbol: [?]
locale:[zh_CN.utf8], international currency symbol: [CNY ]
locale:[zh_HK.utf8], currency symbol: [HK$]
locale:[zh_HK.utf8], international currency symbol: [HKD ]
locale:[zh_TW.big5], currency symbol: [NT$]
locale:[zh_TW.big5], international currency symbol: [TWD ]
locale:[fr_BE.iso88591], currency symbol: [EUR]
locale:[fr_BE.iso88591], international currency symbol: [EUR ]

为什么每个“国际货币符号”都以空格字符结尾?我对结果很困惑,谁能给我一些帮助?

4

1 回答 1

2

它只是用作分隔符。两个单词之间最常见的分隔符是空格。

int_curr_symbol 后跟国际货币符号。这必须是一个 4 个字符的字符串,其中包含 ISO 4217 标准定义的国际货币符号(三个字符),后跟一个分隔符。资料来源:http ://www.tin.org/bin/man.cgi?section=5&topic=LOCALE

阅读: http: //ftp.gnu.org/old-gnu/Manuals/glibc-2.2.3/html_node/libc_111.html

于 2012-09-25T09:29:14.583 回答