Categories:
.NET (357)
C (330)
C++ (183)
CSS (84)
DBA (2)
General (7)
HTML (4)
Java (574)
JavaScript (106)
JSP (66)
Oracle (114)
Perl (46)
Perl (1)
PHP (1)
PL/SQL (1)
RSS (51)
Software QA (13)
SQL Server (1)
Windows (1)
XHTML (173)
Other Resources:
How can I print a character in a printf format string?
How can I print a '%' character in a printf format string? I tried \%, but it didn't work.
✍: Guest
Simply double the percent sign: %% .
The reason it's tricky to print % signs with printf is that % is essentially printf's escape character. Whenever printf sees a %, it expects it to be followed by a character telling it what to do next. The two-character sequence %% is defined to print a single %.
To understand why \% can't work, remember that the backslash \ is the compiler's escape character, and controls how the compiler interprets source code characters at compile time. In this case, however, we want to control how printf interprets its format string at run-time. As far as the compiler is concerned, the escape sequence \% is undefined, and probably results in a single % character. It would be unlikely for both the \ and the % to make it through to printf, even if printf were prepared to treat the \ specially.
2015-11-09, 1396👍, 0💬
Popular Posts:
How can we know the number of days between two given dates in PHP? Simple arithmetic: <?php $...
Can one execute dynamic SQL from Forms? Yes, use the FORMS_DDL built-in or call the DBMS_SQL databas...
What is triple constraint triangle in project management ? Project Management triangle is depicted a...
Does it matter in what order catch statements for FileNotFoundException and IOExceptipon are written...
I am trying to assign a variable the value of 0123, but it keeps coming up with a different number, ...