print % in c

Robert Earl rearl at geech.ai.mit.edu
Tue Feb 26 05:44:51 AEST 1991


In article <1991Feb25.180600.5004 at ux1.cso.uiuc.edu> gordon at 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



More information about the Comp.lang.c mailing list