Mail Archives: djgpp/2002/02/25/08:08:35
In article <003601c1bd50$1f59d9a0$088f6518 AT mtww DOT phub DOT net DOT cable DOT rogers DOT com> you wrote:
> Thanks for the response Hans-Bernhard. It was much appreciated.
> However, the printf( "\ncharacter %n == %s ", i, ch[i] ) ; in the loop was
> intended to dump the character to the screen and not put it into a
> file.......
I know. But you saw that this worked, and the other didn't. That
should have told you something... printf() is exactly equivalent to
fprintf(stdout, ...), so whatever works with printf() will work with
fprintf(), too.
> How do I put a percent (%) character into a file?
Well, let me quote the C FAQ on you, which you really should have
consulted yourself before posting this question (and to the wrong
newsgroup, too, BTW):
12.6: How can I print a '%' character in a printf format string? I
tried \%, but it didn't work.
A: Simply double the percent sign: %% .
\% can't work, because the backslash \ is the *compiler's*
escape character, while here our problem is that the % is
essentially printf's escape character.
See also question 19.17.
References: K&R1 Sec. 7.3 p. 147; K&R2 Sec. 7.2 p. 154; ISO
Sec. 7.9.6.1.
More generally: simply don't do it that way. Use a printf "%s" format
specifier, or fputs(), fputc(), or any of their brethren.
--
Hans-Bernhard Broeker (broeker AT physik DOT rwth-aachen DOT de)
Even if all the snow were burnt, ashes would remain.
- Raw text -