I am working with a vendor that is running on Windows and expects text in UTF16. I'm running on Linux and it's UTF8. I'm trying to use iconv to convert from UTF8 to UTF16 so I can send over a socket connection. I found an article here stackOverflow, and tried to follow that code but nothing is returned from my function. Has anyone had any experience converting from UTF-8 to UTF-16? thanks.
char * Convert( char *from_charset, char *to_charset, char *input )
{
size_t input_size, output_size, bytes_converted;
char * output;
char * tmp;
iconv_t cd;
cd = iconv_open( to_charset, from_charset);
if ( cd == (iconv_t) -1 )
{
//Something went wrong with iconv_open
if (errno == EINVAL)
{
char * buffer;
sprintf(buffer, "Conversion from %s to %s not available", from_charset, to_charset);
cout << buffer << endl;
}
return NULL;
}
input_size = strlen(input);
output_size = 2 * input_size;
output = (char*) malloc(output_size+1);
bytes_converted = iconv(cd, &input, &input_size, &output, &output_size);
cout << "Bytes converted: " << bytes_converted << endl;
if ( iconv_close (cd) != 0)
cout<< "Error closing iconv_error" << endl;
return output;
}