print % in c

Richard A. O'Keefe ok at goanna.cs.rmit.oz.au
Thu Feb 28 12:33:56 AEST 1991


In article <RICHARD.91Feb27110730 at laplace.iesd.auc.dk>, richard at iesd.auc.dk (Richard Flamsholt S0rensen) writes:
> > 	printf("This a percent sign: \%\n");
> > 	printf("This is a backslash: \\\n");
> 
> Richard> Did you *try* this?  Backslash is handled by one of the compiler
> Richard> phases.  The string "This is a percent sign \%\n" turns into the
> Richard> characters <T,h,i,s, ,i,s, ,a, ,p,e,r,c,e,n,t, ,s,i,g,n, ,%,NEWLINE>
> 
>   Did *you* try this? Backslash doesn't by any means "protect the next
> char" - it handles a limited number of predefined escape sequences.

Yes I ***DID*** try it.  Nowhere did I state or imply that backslash
"protects the next char".  The correct statement is
	"The effect of backslash is *PARTIALLY* defined in the ANSI C
	standard.  \% is *NOT* defined.  However, UNIX compilers have
	historically treated \@ just like @ whenever @ is not one of
	the characters whose effect is officially defined.  So while
	a compiler may do anything at all when it comes across  \%,
	it is most likely to treat it just like %."
There.  Will that do?  (What's more, I tried it under several compilers
before I posted.  Sadly, all were pcc-based.)

-- 
The purpose of advertising is to destroy the freedom of the market.



More information about the Comp.lang.c mailing list