Use iconv API in C

Posted by Constantin on Stack Overflow See other posts from Stack Overflow or by Constantin
Published on 2010-12-24T03:06:22Z Indexed on 2010/12/24 3:54 UTC
Read the original article Hit count: 420

Filed under:
|

I try to convert a sjis string to utf-8 using the iconv API. I compiled it already succesfully, but the output isn't what I expected. My code:

void convertUtf8ToSjis(char* utf8, char* sjis){
  iconv_t icd;
  int index = 0;
  char *p_src, *p_dst;
  size_t n_src, n_dst;
  icd = iconv_open("Shift_JIS", "UTF-8");
  int c;
  p_src = utf8;
  p_dst = sjis;
  n_src = strlen(utf8);
  n_dst = 32; // my sjis string size
  iconv(icd, &p_src, &n_src, &p_dst, &n_dst);
  iconv_close(icd);
}

I got only random numbers. Any ideas?

Edit: My input is

char utf8[] = "\xe4\xba\x9c";       //?

And output should be: 0x88 0x9F

But is in fact: 0x30 0x00 0x00 0x31 0x00 ...

© Stack Overflow or respective owner

Related posts about unicode

Related posts about shift-jis