Using printf() with unicode

UTF8 is a bitch, but it solves alot of your problems. Starting to use wide-string UTF8 functions and data types isn't hard but sometimes little things can really catch you out.

Like when you want to use printf() to stick a string into a format.

Using the usual "%s" will only display the first character. You need to tell the formatter that you're expecting a wide string instead using "%ls".

wsprintf(output, L"new format: %ls", strInput);
wsprintf(output, _TEXT("new format: %ls"), strInput);

 
Copyright © Twig's Tech Tips
Theme by BloggerThemes & TopWPThemes Sponsored by iBlogtoBlog