cancel
Showing results for 
Search instead for 
Did you mean: 

When use Unicode::snprintf and Unicode::strncpy

nico23
Senior III

I'm having a hard time understanding when to use Unicode::snprintf vs Unicode::strncpy, also because I'm seeing different behavior when it comes to wildecards.

I have a font where I've set various wildcard characters (see below)

nico23_0-1763548933387.png

Now, I have a text area with a buffer of 10.

If I use 

Unicode::snprintf(myTextBuffer, MYTEXTTEXT_SIZE, "%s", "myText");

I'm seeing the text on the touchscreen as ???, so it basically falls back to the fallback characters.

Instead, if I use 

Unicode::strncpy(myTextBuffer, "myText", MYTEXTTEXT_SIZE);

 I correctly see myText as the text

Why is that?

1 REPLY 1
ferro
Lead

Hi @nico23 

>>" I correctly see myText as the text"

That is because strncpy is overloaded and correct version is picked by compiler#

\include\touchgfx\Unicode.hp

ferro_0-1763565838315.png

However, Unicode::snprintf() expects Unicode string so add preffix 'u' e.g. u"unicode text char16_t"

 

Unicode::snprintf(myTextBuffer, MYTEXTTEXT_SIZE, "%s", u"myText");