Foolish question

This is a discussion on Foolish question within the C Programming forums, part of the General Programming Boards category; For some reason, I can't remember how to printf a %. If I use something like Code: printf("20\%"); I just ...

  1. #1
    Registered User
    Join Date
    Nov 2005
    Posts
    18

    Foolish question

    For some reason, I can't remember how to printf a %. If I use something like
    Code:
    printf("20\%");
    I just get nonsense. I'm just picking c back up, so some things are forgotten :S

    Any help appreciated

  2. #2
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,822
    Use %% to get one %
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.
    I support http://www.ukip.org/ as the first necessary step to a free Europe.

  3. #3
    Registered User
    Join Date
    Nov 2005
    Posts
    18
    Many thanks.

  4. #4
    Registered User
    Join Date
    Aug 2007
    Location
    Barbados
    Posts
    31
    to print one %, use two.
    Code:
    printf("%%");

  5. #5
    Algorithm Dissector iMalc's Avatar
    Join Date
    Dec 2005
    Location
    New Zealand
    Posts
    6,308
    In general it is safer to use:
    Code:
    printf("&#37;s", "<whatever you like goes here as none of this gets touched %s%f%d%.4u%%>");
    My homepage
    Advice: Take only as directed - If symptoms persist, please see your debugger

    Linus Torvalds: "But it clearly is the only right way. The fact that everybody else does it some other way only means that they are wrong"

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Alice....
    By Lurker in forum A Brief History of Cprogramming.com
    Replies: 16
    Last Post: 06-20-2005, 03:51 PM
  2. Debugging question
    By o_0 in forum C Programming
    Replies: 9
    Last Post: 10-10-2004, 06:51 PM
  3. Question about pointers #2
    By maxhavoc in forum C++ Programming
    Replies: 28
    Last Post: 06-21-2004, 01:52 PM
  4. Question...
    By TechWins in forum A Brief History of Cprogramming.com
    Replies: 16
    Last Post: 07-28-2003, 10:47 PM
  5. Question, question!
    By oskilian in forum A Brief History of Cprogramming.com
    Replies: 5
    Last Post: 12-24-2001, 01:47 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21