Path: utzoo!utgpu!news-server.csri.toronto.edu!cs.utexas.edu!sdd.hp.com!samsung!munnari.oz.au!goanna!ok From: ok@goanna.cs.rmit.oz.au (Richard A. O'Keefe) Newsgroups: comp.lang.c Subject: Re: print % in c Message-ID: <4829@goanna.cs.rmit.oz.au> Date: 26 Feb 91 09:50:19 GMT References: <61516@eerie.acsu.Buffalo.EDU> <1991Feb25.180600.5004@ux1.cso.uiuc.edu> Organization: Comp Sci, RMIT, Melbourne, Australia Lines: 15 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"); 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 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.