www.delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/2002/02/25/08:08:35

X-Authentication-Warning: delorie.com: mailnull set sender to djgpp-bounces using -f
Date: Mon, 25 Feb 2002 13:08:51 +0100
Message-Id: <200202251208.NAA23671@acp3bf.physik.rwth-aachen.de>
From: Hans-Bernhard Broeker <broeker AT physik DOT rwth-aachen DOT de>
To: djgpp AT delorie DOT com
Subject: Re: String Problems
X-Newsgroups: comp.os.msdos.djgpp
In-Reply-To: <003601c1bd50$1f59d9a0$088f6518@mtww.phub.net.cable.rogers.com>
Reply-To: djgpp AT delorie DOT com
Errors-To: nobody AT delorie DOT com
X-Mailing-List: djgpp AT delorie DOT com
X-Unsubscribes-To: listserv AT delorie DOT com

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 -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019