0

Hello I am new to most coding and i am writing code onto PSoC4 creator for PSoC 3 chip that uses sprintf to display a string to LCD but my function looks like

sprintf(line1Str,"Local T" );           //TOP row of LCD                        
sprintf(line2Str,"TL=%.1f", CurrentTemp ) //Bottom row of LCD

My problem is that i want to be able to display the % sign in this as well as floating point. I have tried the special character stuff like Char38 and so forth and leaving white space and such but it seams to skip when i have this style of format. can anyone help me?

gsamaras
  • 71,951
  • 46
  • 188
  • 305
Xanthius
  • 17
  • 5

2 Answers2

1

To display the % character in a string created or outputted by a printf-family function, use the %% escape sequence:

printf("Your grade is 100%% on this assignment\n");

Output:

Your grade is 100% on this assignment

See this page, particularly the last entry in the first table:

A % followed by another % character will write a single % to the stream.

Govind Parmar
  • 20,656
  • 7
  • 53
  • 85
  • Thanks I tried the double %% infront of it with the call to the float but not after thanks its working now much appreciated!! – Xanthius Jun 07 '17 at 21:24
1

Use %% like this:

sprintf(line2Str,"TL=%%%.1f", CurrentTemp );

Note that need one percentage character for the float number as well.

gsamaras
  • 71,951
  • 46
  • 188
  • 305