Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. printf in C

printf in C

Scheduled Pinned Locked Moved C / C++ / MFC
helpquestion
4 Posts 4 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • A Offline
    A Offline
    Anonymous
    wrote on last edited by
    #1

    Hai, I want to print % symbol in my printf statement.. eg : printf(" Error is %.2f %",val); ie it should print Error is 5.00% How should I do this?? thanks.

    T R 2 Replies Last reply
    0
    • A Anonymous

      Hai, I want to print % symbol in my printf statement.. eg : printf(" Error is %.2f %",val); ie it should print Error is 5.00% How should I do this?? thanks.

      T Offline
      T Offline
      Tyrus182
      wrote on last edited by
      #2

      in order to print a % use \% if you wannt print a \ do \\ or a quote mark would be \" they are all escape sequances similar to \n or \r

      1 Reply Last reply
      0
      • A Anonymous

        Hai, I want to print % symbol in my printf statement.. eg : printf(" Error is %.2f %",val); ie it should print Error is 5.00% How should I do this?? thanks.

        R Offline
        R Offline
        Ryan Binns
        wrote on last edited by
        #3

        Using %% in the format string will output a single % symbol. So your format string should be " Error is %.2f %%".

        Ryan

        "Punctuality is only a virtue for those who aren't smart enough to think of good excuses for being late" John Nichol "Point Of Impact"

        A 1 Reply Last reply
        0
        • R Ryan Binns

          Using %% in the format string will output a single % symbol. So your format string should be " Error is %.2f %%".

          Ryan

          "Punctuality is only a virtue for those who aren't smart enough to think of good excuses for being late" John Nichol "Point Of Impact"

          A Offline
          A Offline
          Andrzej Markowski
          wrote on last edited by
          #4

          Or use %c in the format string printf(" Error is %.2f %c",val,'%'); Regards, Andrzej Markowski

          My Latest ArticlesCCustomBitmapButton: An owner-draw button and a frame for the caption bar, in one class. CCustomTabCtrl: A clone of the Excel tab sheet control.

          1 Reply Last reply
          0
          Reply
          • Reply as topic
          Log in to reply
          • Oldest to Newest
          • Newest to Oldest
          • Most Votes


          • Login

          • Don't have an account? Register

          • Login or register to search.
          • First post
            Last post
          0
          • Categories
          • Recent
          • Tags
          • Popular
          • World
          • Users
          • Groups