Path: utzoo!news-server.csri.toronto.edu!cs.utexas.edu!uunet!seismo!dimacs.rutgers.edu!rutgers!modus!simm!yachaya!oliver!newsuser From: newsuser@oliver.SUBLINK.ORG (Ugo Cei) Newsgroups: comp.lang.c Subject: Re: print % in c Message-ID: <875@oliver.SUBLINK.ORG> Date: 2 Mar 91 09:55:41 GMT References: <61516@eerie.acsu.Buffalo.EDU> <4843@goanna.cs.rmit.oz.au> <1991Feb28.042409.14007@usenet.ins.cwru.edu> Organization: Oliver, Pavia, Italy Lines: 32 dean@usenet.INS.CWRU.Edu (Dean Cookson) writes: >In article <4843@goanna.cs.rmit.oz.au> ok@goanna.cs.rmit.oz.au (Richard A. O'Keefe) writes: >[Stuff Deleted] >> 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.) >> >Nope, sorry but it won't. You had me up to the "most likely" part. The >behavior is undefined. (See section A.2.5.2 Character Constants of the >Ref. Manual in K&R 2) What the compiler is most likely to do is something >random. (ie your pcc based compilers like it, gcc gives a warning then >doesn't print it. Sun cc gives no warning, then doesn't print it) I think Richard is right on this one. What he was saying is that the *compiler* is likely to treat "\%" as "%". Obviously, when *printf* sees it, it does not know what to do and so it is likely to print nothing at all. This is true under SCO's rcc, MSC 5.1 and gcc 1.39 (which indeed gives a warning : "unknown escape sequence `\%'"). The following line of code will print the `%' under any of the three mentioned compilers. (I presume Sun cc will do the same.) fputs("This is a percent sign: \%\n", stdout); However, I certainly don't think that this is a good and/or portable thing to do. -- **************** | Ugo Cei | SUBLINK: newsuser@oliver.sublink.org * OLIVER * | Via Colombo 7 | INTERNET: cei@ipvvis.unipv.it **************** | 27100 Pavia ITALY | "Real Programs Dump Core"