• C

C: double percent sign (%%) in printf() statement (and question about %3.2f)

Hey all,

Need a sanity check here.

In this statement:

printf(,"Percent Completed %3.2f%%\r",percent);

Am I correct in deducing that the %% is necessary to display a percent sign, to avoid a single % from being taken to be a format specifier?  

Yeah, I know I should know this, but I'm reviewing a C file to be sure that there are no mismatched format specifiers (b/c the program occasionally crashes) and want to be sure this statement is OK.

In addition, is the %3.2f format specifier OK for a double, as well as a float? (This question applies to both 16-bit and 32-bit).

Thanks
Steve
LVL 4
Stephen KairysTechnical Writer - ConsultantAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

mccarlIT Business Systems Analyst / Software DeveloperCommented:
Correct, the double %% means to output a literal (single) % rather than it being a format specifier.

Refer to the man page...  http://linux.die.net/man/3/printf   (Specifically, just above the "Conforming To" large heading is where it gives you this information)
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Stephen KairysTechnical Writer - ConsultantAuthor Commented:
Thank you. And to this question:

>>In addition, is the %3.2f format specifier OK for a double, as well as a float? (This question >>applies to both 16-bit and 32-bit).

Thanks again.
Steve
0
mccarlIT Business Systems Analyst / Software DeveloperCommented:
In addition, is the %3.2f format specifier OK for a double, as well as a float?
Actually, it ONLY uses a double argument. And if you pass a float argument to printf it will automatically be promoted to be a double so that printf can use it.
0
Stephen KairysTechnical Writer - ConsultantAuthor Commented:
Thank you for the speedy and helpful responses! Have a good evening.
-Steve
0
mccarlIT Business Systems Analyst / Software DeveloperCommented:
You're welcome! :)
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
C

From novice to tech pro — start learning today.