ユーザ用ツール

サイト用ツール


iconv

目次

iconv

文字コードの変換。

linux のコマンド、あるいはライブラリ。

jagtalk ではこんな使い方をしている。

http://github.com/nishimotz/jagtalk/blob/master/util.c

# include <iconv.h>
# define ICONV_BUFSIZE 4096
//
        char orig_buf[ICONV_BUFSIZE];
        char buf[ICONV_BUFSIZE];
        // orig_buf に文字列をコピー
        iconv_t m_iconv = iconv_open("UTF-8", "EUC-JP"); // tocode, fromcode
        size_t in_size = (size_t)ICONV_BUFSIZE;
        size_t out_size = (size_t)ICONV_BUFSIZE;
        char *in = orig_buf;
        char *out = buf;
        iconv(m_iconv, &in, &in_size, &out, &out_size);
        iconv_close(m_iconv);
        fputs( buf, stdout );
	fflush( stdout );

http://github.com/nishimotz/jagtalk/blob/master/getline.c

        char read_buf[ICONV_BUFSIZE];
	fgets( read_buf, ICONV_BUFSIZE, stdin );
	if( read_buf == NULL) return -1;
        iconv_t m_iconv = iconv_open("EUC-JP", "UTF-8"); // tocode, fromcode
        size_t in_size = (size_t)ICONV_BUFSIZE;
        size_t out_size = (size_t)MAX_LENGTH;
        char *in = read_buf;
        char *out = buf;
        iconv(m_iconv, &in, &in_size, &out, &out_size);
        iconv_close(m_iconv);
	int p = strlen( buf ) - 1;
	if( buf[p] == '\n' )  buf[p] = '\0';
	return p;
iconv.txt · 最終更新: 2010/06/29 13:04 (外部編集)

Donate Powered by PHP Valid HTML5 Valid CSS Driven by DokuWiki