swprintf doesn't works, always returns garbage, on NDK8d with STLPORT

498 views
Skip to first unread message

Whiso

unread,
Feb 27, 2013, 11:03:04 PM2/27/13
to andro...@googlegroups.com
Hi!!
I'm using wchars string, i need to format string, but when the function swprintf is used, this returns incorrect characters, I'm using STLPORT and NDK8d,
why this function does't work yet!!

Cheers!!

Jeffrey Walton

unread,
Feb 27, 2013, 11:18:39 PM2/27/13
to andro...@googlegroups.com
How does it return incorrect characters?

Are you using it correctly? To use s{w}printf correctly, use element
counts (not byte counts). The function returns -1 on failure, and the
number of required character. Truncation occurs when 'required >=
given'. So:

wchar_t buffer[256]
size = COUNTOF(buff); // 256; not sizeof(x) !!!
int written = swprintf(buffer, size "%s", <some wide string>);
if(-1 == written || written >= COUNTOF(buff))
abort(); // Failed

Here's a reference, but its kind of broken since it does not tell you
about truncation: http://www.cplusplus.com/reference/cwchar/swprintf/.

If you are defining NDK_DEBUG, you should also define _STLP_DEBUG=1
when using STLPort. You might get an assert or debug diagnostic
message.

Jeff

Whiso

unread,
Mar 7, 2013, 12:52:48 AM3/7/13
to andro...@googlegroups.com
Thanks a lot, for your replies, I had to change this function by other one to fix this problem, but i think this function is very important because almost all app supports 
multi-language , so if our app needs to manage all languages in unicode, that's a big trouble

Tor Lillqvist

unread,
Mar 8, 2013, 6:43:37 AM3/8/13
to andro...@googlegroups.com
so if our app needs to manage all languages in unicode, that's a big trouble

Have you heard of UTF-8? 

--tml

Whiso

unread,
Mar 9, 2013, 9:00:17 PM3/9/13
to andro...@googlegroups.com
Yep!! I had to change unicode string to UTF-8 but i had fix on my function to paint letters on screen to use UTF-8
Reply all
Reply to author
Forward
0 new messages