Skip to main content
Ezgi
Associate III
April 29, 2021
Solved

printing a string

  • April 29, 2021
  • 1 reply
  • 1394 views

Hi,

I'm trying to print the string. What is that I'm missing?

This is my func :

void Screen1View::UpdateWildcardTexts(char* a)
{
	Unicode::snprintf(textArea1Buffer,10,"%s",a);
	textArea1.invalidate();
}

This is how I test it :

void Screen1View::setupScreen()
{
	Screen1ViewBase::setupScreen();
	char a[16] = "string";
	UpdateWildcardTexts(a);
}

This topic has been closed for replies.
Best answer by Michael K

touchgfx::Unicode::snprintf only supports the %s format with UnicodeChar arguments. You should use touchgfx::Unicode::strncpy instead to fill the buffer with your char array.

touchgfx::Unicode::strncpy(textArea1Buffer, a, 10);

If you really want to use snprintf, convert it to a UnicodeChar first.

void Screen1View::UpdateWildcardTexts(const char* a)
{
	touchgfx::Unicode::UnicodeChar b[10];
	touchgfx::Unicode::strncpy(b, a, 10);
	touchgfx::Unicode::snprintf(textArea1Buffer,10,"%s",b);
	textArea1.invalidate();
}

Sidenote: @Martin KJELDSEN​ I see that anchor links in tgfx documentation still don't work =)

1 reply

Michael K
Michael KBest answer
Senior III
April 29, 2021

touchgfx::Unicode::snprintf only supports the %s format with UnicodeChar arguments. You should use touchgfx::Unicode::strncpy instead to fill the buffer with your char array.

touchgfx::Unicode::strncpy(textArea1Buffer, a, 10);

If you really want to use snprintf, convert it to a UnicodeChar first.

void Screen1View::UpdateWildcardTexts(const char* a)
{
	touchgfx::Unicode::UnicodeChar b[10];
	touchgfx::Unicode::strncpy(b, a, 10);
	touchgfx::Unicode::snprintf(textArea1Buffer,10,"%s",b);
	textArea1.invalidate();
}

Sidenote: @Martin KJELDSEN​ I see that anchor links in tgfx documentation still don't work =)

Embedded UI/UX Consulting: cadenza.design
Ezgi
EzgiAuthor
Associate III
April 30, 2021

Thank you for your answer. I tried to use strncpy(), but I got fallback character even I wrote A-Z into Wilcard Ranges. Now I just wrote a-z into Wilcard Ranges and I could see the "string".