Path: utzoo!utgpu!news-server.csri.toronto.edu!cs.utexas.edu!sdd.hp.com!zaphod.mps.ohio-state.edu!pacific.mps.ohio-state.edu!linac!att!cbnewsl!cbnewsk!ech From: ech@cbnewsk.att.com (ned.horvath) Newsgroups: comp.sys.mac.programmer Subject: Re: New Think C user Message-ID: <1991Feb8.211648.2934@cbnewsk.att.com> Date: 8 Feb 91 21:16:48 GMT References: <21005@sri-unix.SRI.COM> Organization: AT&T Bell Laboratories Lines: 34 From article <21005@sri-unix.SRI.COM>, by mxmora@sri-unix.SRI.COM (Matt Mora): > ...Why do you have to use > a double percent sign in a string literal to have it print a percent sign > when all logic would indicate that a backslash percent sign should work? > > Example: > Anytime you want to include a special character you preceede it with > a back slash. > > printf("this will beep\a"); > > printf("this will tab\tthis part over"); > > printf("you are %d years old.\n",age); > > So you would think that since the percent sign is the mask in a string literal > that if a backslash was before it, the compiler would do the right thing. > > printf("this won't work %d\%percent",intrate); > > This wll actually print out a pointer from who knows where. > > printf("this does work %d %%percent",intrate) The compiler does the right thing: \n, \t and the rest are special to the compiler, which builds the appropriate control character into the string constant. \% isn't special to the compiler, so it just puts % into the format string. % IS important to printf, which scans the format string for goodies (printf never sees a \ unless you code \\, OK?). Hope that helps... =Ned Horvath= ehorvath@attmail.com