cancel
Showing results for 
Search instead for 
Did you mean: 

printing a string

Ezgi
Senior

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);
}

1 ACCEPTED SOLUTION

Accepted Solutions
Michael K
Senior III

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

View solution in original post

2 REPLIES 2
Michael K
Senior III

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

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".