Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // iconv_test.c -*- encoding: utf-8 -*-
- // gcc iconv_test.c && (./a.out | nkf -g)
- #include <stdio.h>
- #include <stdlib.h>
- #include <unistd.h>
- #include <string.h>
- #include <errno.h>
- #include <iconv.h>
- #define SIZE 1024
- int main(int argc, char *argv[])
- {
- char *src, dst[SIZE];
- char *p_src, *p_dst;
- size_t src_len;
- size_t dst_len, dst_len_orig;
- size_t result;
- iconv_t cd;
- src = (argv[1] != NULL) ? argv[1] : "こんなテストで大丈夫か?";
- p_src = src;
- src_len = strlen(src);
- memset(dst, 0, SIZE);
- p_dst = dst;
- dst_len = SIZE - 1;
- dst_len_orig = dst_len;
- cd = iconv_open("UTF-32LE", "UTF-8");
- result = iconv(cd, &p_src, &src_len, &p_dst, &dst_len);
- if (result == -1) {
- perror("iconv");
- exit(-1);
- }
- *p_dst = '\0';
- write(STDOUT_FILENO, dst, (dst_len_orig - dst_len));
- iconv_close(cd);
- return 0;
- }
Add Comment
Please, Sign In to add comment