Sunday, May 10, 2009

How do you printf quotation marks " " in C?

I know that to print a message we use printf (" message" );





but how do you print quotation marks? I tried with Dev-C typing printf (" "message" "); it does not work.

How do you printf quotation marks " " in C?
Simple think


In C, since for next line we have the \n, for tab \t, for alarm \a etc, we have \" for including the Double quotes symbol for printing.





Like printf("\" Hello World\"");


will give the output as





"Hello World".
Reply:printf("\"Hello World\"");


:)
Reply:Every language has a way of 'escaping' delimeters. In most implementations of C, this is the backslash. This is not always true so you need to make sure you know the escape characters of the language you happen to be using at the time. Here's how it works in most C compilers.





printf("She said, \"why?\"");





would result in the sentence:


She said, "Why?"
Reply:To print quotation marks you \" the \ tells the c compiler to honor the quotation marks and not to use them as delimiters.
Reply:Hello,





You need to read more about the C language. I suggest to start learning, rather than wasting too much time on figuring out language-dependent stuff.





These links may be helpful:





http://www.imada.sdu.dk/~svalle/courses/...





http://www.acm.uiuc.edu/webmonkeys/book/...





Thanks
Reply:You must have heard of 'Escape Sequences' in programming world. These are special symbols that change the normal meaning of other symbols. In C, a back slash is an escape sequence. For example in C string lower case n means letter n but if you write \n, its meaning is changed to be line feed character. the same case is with \r for carriage return, \t for tab and so on.





So, In C/C++ a double quote has a normal meaning of string delimiter, that is, this symbol tells compiler the start and end of string. So what should we do if we really want to print this character as part of string? Don't worry, here comes the escape sequence \. if your put \ before " it escapes its normal meaning (string delimiter) and tells compiler to take it as a character that is part of string. so





printf("\"London\""); will pring "London"





and





printf("This is a \"Very Good\" idea"); will print This is a "Very Good" idea





Hope that answers the question
Reply:put a slash in front of the double quote like this, \"


In C, you would use slash to escape certain special characters.

love song

No comments:

Post a Comment