
Formatted print with % as a printed character

ssmith911
HI-- I'm trying to print to a notebook or in the command window something that would look like this: "Bob 78% 66%" I'm guessing that the % after the first %d is causing me to get a "format string invalid" error message. I can get around this by doing 2 printfs without the end carriage return but that seems kind of cluegy. Is there a more elegant, ie correct, way of doing this. What is shown below doesn't work.
string name = "Bob" variable meetstat=78 variable campstat = 60 printf "%s \t\t %d% \t\t\t\t%d% \r",name, meetstat, campstat
Any advice is, as always, very much appreciated. Thanks
ssmith
Try:
October 24, 2018 at 06:54 am - Permalink
KurtB--
Thats the ticket!! Thanks a lot. Can you explain the logic/reason that this works? That is to say the IGOR logic that is taking place? Thanks again.
ssmith
October 24, 2018 at 07:53 am - Permalink
This is a feature of Printf. Since % has special interpretation, we need a way to represent a literal % character.
This is stated in the documentation for Printf, but it could be more explicit. See the section that starts "Here is a complete list of the conversion characters supported by printf". It lists all of the "conversion characters", i.e., characters that follow a % character that starts a conversion sequence.
Among the listed conversion characters is %. This means that you have the % character that introduces the conversion sequence followed by another % character.
As I say, it could be more explicit. I have made a note to improve the documentation.
October 24, 2018 at 09:28 am - Permalink
hrodstein--
Thanks a lot for the clarification.
ssmith
October 24, 2018 at 11:57 am - Permalink