Print Char '%' in formated output

Go To Last Post
4 posts / 0 new
Author
Message
#1
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Hello All,

 

I want to print the character '%' in sprintf. How can I achieve this?

friendly regards

Ellen

 

sprintf(s,"PV %dWh P %dWh b %dA %d%", (int)SumPv, (int)SumLinePowerBat, (int)Charge_DischargePowerTotal, PercentBatCap);

the output should be at the last item: 45%. The compiler ignores the last char and gives me this warning:

Severity

Code

Description

Project

File

Line

Warning

 

spurious trailing '%' in format [-Wformat=]

SolarmonV02

C:\Users\User2\Documents\Atmel Studio\7.0\Solarmon\SolarmonV02\Utils.c

 

 

 

138

 

This topic has a solution.
Last Edited: Thu. Oct 17, 2019 - 10:51 AM
This reply has been marked as the solution. 
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

http://www.cplusplus.com/reference/cstdio/printf/

 

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

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Oh,

very good. It works

 

thanks Ellen