%% in printf

R

Ravi

I hope this is not a FAQ.

printf("%%%%");

What is the output for this? Is it implementation dependent?

TIA.
 
S

Sheldon Simms

I hope this is not a FAQ.

printf("%%%%");

What is the output for this? Is it implementation dependent?

TIA.

If you don't have a book that covers this sort of thing, go buy
one as soon as possible. ok?

In the meantime, here are some excerpts from the standard:

ISO/IEC 9899:1999 (E)

7.19.6.1

4 Each conversion specification is introduced by the character %.

8 The conversion specifiers and their meanings are:

% - A % character is written. No argument is converted. The complete
conversion specification shall be %%.
 
S

Servé Laurijssen

Ravi said:
I hope this is not a FAQ.

printf("%%%%");

What is the output for this? Is it implementation dependent?

Yes, only after adding '\n' it will most certainly output %%, otherwise you
need fflush(stdout) to make it print %%
 
G

Glen Herrmannsfeldt

Servé Laurijssen said:
Yes, only after adding '\n' it will most certainly output %%, otherwise you
need fflush(stdout) to make it print %%

Or end the program? I believe open files are flushed and closed when the
program end.

I have a number of times run into this problem in Java, where buffers are
not flushed and files closed, unless one explicitly closes them. (Close
does flush, yes.) It doesn't seem like too much to ask to me.

-- glen
 
P

Peter Nilsson

Servé Laurijssen said:
Yes, only after adding '\n' it will most certainly output %%, otherwise you
need fflush(stdout) to make it print %%

Technically, the fflush is still insufficient to guarantee output of
the last line of a text stream. [However, it does typically address
the issue for consoles where it is a problem.]
 
T

Tristan Miller

Greetings.

When you say "yes" are you saying that it is implementation
dependent?

Yes, he is. (Given that there was only one yes-no question in your
original post, it's difficult to fathom what other interpretation one
could give this answer.)
 
S

Servé Lau

Ravi said:
When you say "yes" are you saying that it is implementation
dependent?

yes, but not in the manner you expected I guess. %% will print one % with
printf, but it's possible that nothing is printed if you omit the \n
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,582
Members
45,067
Latest member
HunterTere

Latest Threads

Top