This example shows how to convert a Unicode string to code page characters.

#include <stdio.h>
#include <uconv.h>
int main(void) {
UconvObject  uconv_object = NULL;
int          rc = ULS_SUCCESS;
size_t       out_bytes_left;
size_t       uni_chars_left;
size_t       num_subs;
size_t       char_buf_size = 50;
char         char_buffer[50];
char         *pout_char_str;
UniChar      *pin_uni_str;
UniChar      uni_data[] = L"UniCode string to convert";

         /********************************************************************/
         /* Create a conversion object based upon the process code page      */
         /********************************************************************/

         rc = UniCreateUconvObject((UniChar *)L"", &uconv_object);

         if (rc != ULS_SUCCESS) {
           printf("UniCreateUconvObject error: return code = %u\n", rc);
           return 1;
         }
        /*********************************************************************/
        /* pin_uni_str points to the unicode string to be converted to       */
        /* code page characters                                              */
        /*********************************************************************/

        pout_char_str = char_buffer;
        pin_uni_str = uni_data;

        uni_chars_left = UniStrlen(pin_uni_str)+1;
        out_bytes_left = char_buf_size;

        /*********************************************************************/
        /* make call to convert unicode string  to code page characters      */
        /*********************************************************************/

        rc = UniUconvFromUcs(uconv_object, &pin_uni_str, &uni_chars_left,
                            (void **)&pout_char_str, &out_bytes_left,
                            &num_subs);

        if(rc != ULS_SUCCESS && uni_chars_left > 0) {
           printf("UniUconvFromUcs error: return code = %u\n", rc);
           printf("Unicode string was not completely converted\n");
           return 1;
        }
        return ULS_SUCCESS;
}


[Back: UniUconvFromUcs - Related Functions]
[Next: UniUconvFromUcs - Topics]