How to add the % character to a string

Posted on 2005-04-26
Medium Priority
Last Modified: 2012-05-05
fprintf (pFile, "\nEfficiency:   %.1f %c",mynumber,"%")
fprintf (pFile, "\nEfficiency:   %.1f \%",mynumber)
fprintf (pFile, "\nEfficiency:   %.1f %",mynumber)

... none of these work.

output wanted:

Efficiency:     82.2%
Question by:galneweinhaw
  • 2
LVL 30

Expert Comment

ID: 13871297
Hi galneweinhaw,
> >fprintf (pFile, "\nEfficiency:   %.1f %",mynumber)

Use two very every one.
fprintf (pFile, "\nEfficiency:   %.1f %%",mynumber)

David Maisonave :-)
LVL 30

Accepted Solution

Axter earned 800 total points
ID: 13871308
In your string when you need to represent a %, you replace the single character with two of them.

LVL 55

Assisted Solution

by:Jaime Olivares
Jaime Olivares earned 200 total points
ID: 13871338
1rst case would work but with a char argument:
fprintf (pFile, "\nEfficiency:   %.1f %c",mynumber,'%');   // don't use double quotes

2nd and 3rd case won't work, unique alternative (and most used) is what Axter exposed.

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Often, when implementing a feature, you won't know how certain events should be handled at the point where they occur and you'd rather defer to the user of your function or class. For example, a XML parser will extract a tag from the source code, wh…
This article shows you how to optimize memory allocations in C++ using placement new. Applicable especially to usecases dealing with creation of large number of objects. A brief on problem: Lets take example problem for simplicity: - I have a G…
The goal of the video will be to teach the user the concept of local variables and scope. An example of a locally defined variable will be given as well as an explanation of what scope is in C++. The local variable and concept of scope will be relat…
The viewer will be introduced to the technique of using vectors in C++. The video will cover how to define a vector, store values in the vector and retrieve data from the values stored in the vector.
Suggested Courses

862 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question