Aman Jain
Aman Jain

Reputation: 11317

UTF-8 to C/POSIX locale conversion using iconv() fails

I am trying to convert UTF-8 string to C/POSIX locale string
The UTF-8 string is "abc123£" (in bash "abc123\302\243"`)

  1. iconv_open("", "UTF-8"); // "" means default program locale i.e. C
  2. iconv_open("UCS-2LE", "UTF-8");

iconv() is returning EILSEQ to me in case 1, but success in case 2.

What is the reason for this?
Also, how can I successfully convert any UTF-8 string to 'C' locale string.

Upvotes: 1

Views: 1138

Answers (1)

hobbs
hobbs

Reputation: 240829

Because your C locale uses a character set (probably US-ASCII) that doesn't have a character for £, and the string can't be converted without loss.

Upvotes: 1

Related Questions