⑴ linux下编码转换问题,C语言实现,使用iconv函数族
1、iconv的含义是将一个抽象的符号的编码进行转换。
但是如果一个符号比如“个”,可能在BIG5的编码中不存在(繁体字中不同)
GBK包含的是简体字,BIG5包含的是繁体字,Unicode包含全部,
所以
GBK->Unicode,Big5-Unicode (总是OK)
Unicode->GBK (当里面仅包含英文及简体时OK)
Unicode->BIG5 (当里面仅包含英文及繁体时OK)
GBK->Big5 (基本上不行,除非某些字没有特别的简体字)
GBK->Big5是汉字的简繁转换,不是编码转换,简体字转繁体字还有一个问题,一个简体字可能是对应多个繁体字,这种很难转换正确。繁体字转换成简体字相对难度低。
2、#include <iconv.h>
size_t iconv(iconv_t cd,
char **inbuf, size_t *inbytesleft,
char **outbuf, size_t *outbytesleft);
函数原型, outbuf是一个 char **类型
在函数手册中:
The iconv() function converts one multibyte character at a time, and for each character conversion it increments *inbuf and decrements
*inbytesleft by the number of converted input bytes, it increments *outbuf and decrements *outbytesleft by the number of converted
output bytes
⑵ linux之iconv命令
Linux中的iconv命令是一个专为文件编码转换而设计的工具。以下是关于iconv命令的详细解答:
主要功能:
命令格式:
使用示例: