print % in c
Richard A. O'Keefe
ok at goanna.cs.rmit.oz.au
Tue Feb 26 20:50:19 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");
Did you *try* this? Backslash is handled by one of the compiler
phases. The string "This is a percent sign \%\n" turns into the
characters <T,h,i,s, ,i,s, ,a, ,p,e,r,c,e,n,t, ,s,i,g,n, ,%,NEWLINE>
and by the time printf() sees it there is nothing special about the
percent sign. To get a percent sign from printf(), use two % signs:
printf("The original answer was 100%% wrong.\n");
--
The purpose of advertising is to destroy the freedom of the market.
More information about the Comp.lang.c
mailing list