Thread: print double quote inside prinf() function

  1. #1
    Registered User
    Join Date
    Feb 2018
    Location
    San Diego, CA
    Posts
    123

    print double quote inside prinf() function

    Hello all..
    Code:
    void print_commands(void)
    {
    	printf("\nCommands to type:\n");
    	printf("\nMEETING LIST");
    	printf("\nMEETING ADD # MM DD YYYY");
    	printf("\nPRINT FILE #");
    	printf("\nQUIT");
    	printf("\n\n");
    }

    I am looking to fix this line please,

    Code:
    	printf("\nQUIT");
    to output
    Code:
    "QUIT"
    Thanks.

  2. #2
    Guest
    Guest
    You can escape double quotes with a backslash like so:
    Code:
    printf("\n\"QUIT\"");

  3. #3
    Registered User
    Join Date
    Feb 2018
    Location
    San Diego, CA
    Posts
    123
    Adrian, couldn't get that line to work, with or without the '\n'.

  4. #4
    Registered User
    Join Date
    May 2009
    Posts
    4,183
    So, you likely did it wrong or you have a defective compiler.

    Tim S.
    "...a computer is a stupid machine with the ability to do incredibly smart things, while computer programmers are smart people with the ability to do incredibly stupid things. They are,in short, a perfect match.." Bill Bryson

  5. #5
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    28,413
    Quote Originally Posted by _jamie View Post
    Adrian, couldn't get that line to work, with or without the '\n'.
    That's feedback with very low value. It is only useful if there was an obvious error in that example, if not, as stahta01 implied, it probably means that you made a mistake, but no one else knows what mistake that is because you didn't provide any information.

    Post the smallest and simplest program that you expect to compile and run with what Guest suggested, and then post the compile error or the actual (incorrect) output from running that program. For example, this is the smallest and simplest compilable program that demonstrates that I could get that line to work:
    Code:
    #include <stdio.h>
    
    int main(void)
    {
        printf("\n\"QUIT\"");
        return 0;
    }
    Compiling and running the above program gave me this output with a leading blank line:
    Code:
    "QUIT"
    Hence, you can see that Guest's suggestion works as you want, so if it doesn't work, then barring a defective compiler, the error is entirely yours.
    Quote Originally Posted by Bjarne Stroustrup (2000-10-14)
    I get maybe two dozen requests for help with some sort of programming or design problem every day. Most have more sense than to send me hundreds of lines of code. If they do, I ask them to find the smallest example that exhibits the problem and send me that. Mostly, they then find the error themselves. "Finding the smallest program that demonstrates the error" is a powerful debugging tool.
    Look up a C++ Reference and learn How To Ask Questions The Smart Way

  6. #6
    Registered User
    Join Date
    Feb 2018
    Location
    San Diego, CA
    Posts
    123
    Quote Originally Posted by _jamie View Post
    Adrian, couldn't get that line to work, with or without the '\n'.

    I've got the issue to work all. It looks like I was having an issue with my code editor (vim). Program outputs "QUIT" successfully.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. prinf show unknown character
    By clapika in forum C Programming
    Replies: 3
    Last Post: 04-16-2011, 11:02 AM
  2. Why not static const double d = 1.5; inside a class?
    By TriKri in forum C++ Programming
    Replies: 9
    Last Post: 12-08-2009, 04:01 PM
  3. Parsing an escaped quote inside a string
    By emef in forum C Programming
    Replies: 4
    Last Post: 11-02-2009, 03:41 PM
  4. Double print
    By thestrap in forum C Programming
    Replies: 1
    Last Post: 12-05-2007, 07:17 PM
  5. writing double quote & comma delimited files
    By emt in forum C++ Programming
    Replies: 5
    Last Post: 06-30-2003, 12:28 AM

Tags for this Thread