//============================================================================ // Name : Encoder.cpp // Author : Manoj // Version : // Copyright : Your copyright notice // Description : //============================================================================ #include #include #include #include #include #include #include using namespace std; char *character_encoding(char *in_string, char *tocode, char *fromcode) { iconv_t conv_desc; conv_desc = iconv_open(tocode, fromcode); if (conv_desc == (iconv_t) -1) { /* Initialization failure. */ if (errno == EINVAL) { cout << "Conversion from " << fromcode << "to " << tocode << "is not supported" << endl; } else { cout << "Initialization failure: " << strerror(errno) << endl; } // exit ok exit(1); } size_t from_len = strlen(in_string); if (!from_len) { cout << "Input string is empty " << endl; exit(1); } size_t to_len = 2 * from_len; char *out_string = NULL; /* Assign enough space to put the converted string */ out_string = new char[to_len]; size_t outbytesleft; /* Assign enough space to put the converted string */ char *pIn = in_string; char *pOut = out_string; if (iconv(conv_desc, &pIn, &from_len, &pOut, &outbytesleft) == (size_t) -1) { switch (errno) { case EILSEQ: case EINVAL: case E2BIG: cout << "Error: " << strerror(errno) << endl; break; default: cout << "Error" << endl; } // exit ok exit(1); } if (out_string) { return out_string; } else { cout << "Final iconv output is NULL " << endl; } int v; v = iconv_close(conv_desc); if (v != 0) { cout << "iconv_close failed: " << strerror(errno) << endl; // exit ok exit(1); } } int main(int argc, char** argv) { cout << character_encoding(argv[1], argv[3], argv[2]) <