Path: utzoo!utgpu!news-server.csri.toronto.edu!cs.utexas.edu!yale!mintaka!mintaka.lcs.mit.edu!rearl From: rearl@geech.ai.mit.edu (Robert Earl) Newsgroups: comp.lang.c Subject: Re: print % in c Message-ID: Date: 25 Feb 91 18:44:51 GMT References: <61516@eerie.acsu.Buffalo.EDU> <1991Feb25.180600.5004@ux1.cso.uiuc.edu> Sender: daemon@mintaka.lcs.mit.edu (Lucifer Maleficius) Organization: (EVIL!) Lines: 17 In-Reply-To: gordon@osiris.cso.uiuc.edu's message of Mon, 25 Feb 1991 18:06:00 GMT In article <1991Feb25.180600.5004@ux1.cso.uiuc.edu> gordon@osiris.cso.uiuc.edu (John Gordon) writes: | To print special characters with printf(), precede the character | with a \ character. Example: | | printf("This a percent sign: \%\n"); | printf("This is a backslash: \\\n"); The first example doesn't work-- you're still passing a `%' character to printf(), in fact you're passing it a format character with no corresponding argument, which really causes it to barf. As the manual says, passing a double `%' to printf means to print a literal `%' character. And you must escape backslashes in any string constant in source code, not just printf arguments. --robert