Convert char* to wchar* in C

Crupuk picture Crupuk · Jan 28, 2011 · Viewed 52.9k times · Source

I would like to convert a char* string to a wchar* string in C.

I have found many answers, but most of them are for C++. Could you help me?

Thanks.

Answer

Nick Dandoulakis picture Nick Dandoulakis · Jan 28, 2011

Try swprintf with the %hs flag.

Example:

wchar_t  ws[100];
swprintf(ws, 100, L"%hs", "ansi string");