How to handle wide character data received in libcurl

66 views Asked by At

I am trying to make a post request with libcurl using deepl API. I don't know how to handle the wide character data received.

There is a function like this but it can only handle char* type data.

size_t write_callback(void *contents, size_t size, size_t nmemb, void *userp) {
    size_t realsize = size * nmemb;
    printf("%.*s", (int)realsize, (char *)contents);
    return realsize;
}

How can I achieve this with a function.

1

There are 1 answers

0
tonymke On

The C99 standard defines a pair of functions for conversions between wchar_t and char ("multi-byte") strings. You're looking for wcstombs (C99 7.20.8.2) ("wide char string to multi-byte string").

Fortunately, POSIX mirrors the C99 standard here - and unlike C standards, reading POSIX is free. See wcstombs(3).