Printf the % symbol as plain text to a console window

This is a discussion on Printf the % symbol as plain text to a console window within the C Programming forums, part of the General Programming Boards category; Using Vim and gcc in Linux. Code: printf("%d"); What I want that to do is print to a console screen ...

  1. #1
    Registered User
    Join Date
    Feb 2012
    Location
    Pointless details.
    Posts
    2

    Smile Printf the % symbol as plain text to a console window

    Using Vim and gcc in Linux.

    Code:
    printf("%d");
    What I want that to do is print to a console screen like so:

    %d

    Of course it doesn't work like that. The reason I want to do that is so that whenever I want to refer to the special character constants table I can just type a command in a console and up it will pop rather than having to leaf back through a booklet.

    I also tried:
    Code:
    printf("\\%d");  // Which also didn't work.
    I couldn't find the answer to this problem either in my book or on these forums, perhaps I used the wrong search terms. I would be grateful for any help given!

    Thank you, please try to be forgiving as I am new to computers in general

  2. #2
    ATH0 quzah's Avatar
    Join Date
    Oct 2001
    Posts
    14,826
    Use %% if you want one %. printf


    Quzah.
    Hope is the first step on the road to disappointment.

  3. #3
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    21,410
    One way is to print it formatted as a string, e.g.,
    Code:
    printf("%s", "%d");
    Another way, more applicable when you really do want this to be part of a format string, is to escape the %, e.g.,
    Code:
    printf("%%d");
    C + C++ Compiler: MinGW port of GCC
    Version Control System: Bazaar

    Look up a C++ Reference and learn How To Ask Questions The Smart Way

  4. #4
    Registered User
    Join Date
    Feb 2012
    Location
    Pointless details.
    Posts
    2
    Thank you quzah and you too laserlight! I very much appreciate the help both of you have given me!

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Reading plain text into a RichEdit control
    By JustMax in forum C Programming
    Replies: 0
    Last Post: 02-03-2009, 02:15 PM
  2. Extract Title from plain text file
    By Todd88 in forum C++ Programming
    Replies: 10
    Last Post: 11-21-2008, 08:47 AM
  3. retreiving console window text
    By mayhem in forum Windows Programming
    Replies: 2
    Last Post: 09-10-2003, 09:40 PM
  4. Recording console window output to a text file?
    By HolySmiter in forum C++ Programming
    Replies: 3
    Last Post: 02-24-2002, 02:13 PM
  5. Plain Window!
    By Shakespeare in forum Windows Programming
    Replies: 1
    Last Post: 01-20-2002, 11:35 AM

Tags for this Thread


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