在一次面试中,我被问到
使用
printf()
函数打印引号
我不知所措。甚至在他们的办公室里也有一台电脑,他们让我试一试。我试过这样做:
void main()
{
printf("Printing quotation mark " ");
}
但正如我怀疑的那样,它不能编译。当编译器获得第一个"
时,它会认为它是字符串的结尾,但事实并非如此。那么我如何才能做到这一点呢?
发布于 2012-08-02 14:42:03
试试这个:
#include <stdio.h>
int main()
{
printf("Printing quotation mark \" ");
}
发布于 2012-08-02 15:10:28
没有反斜杠,特殊字符具有自然的特殊含义。它们在显示时使用反斜杠打印。
\ - escape the next character
" - start or end of string
’ - start or end a character constant
% - start a format specification
\\ - print a backslash
\" - print a double quote
\’ - print a single quote
%% - print a percent sign
这句话
printf(" \" ");
我会把报价打印出来。您还可以打印这些特殊字符\a、\b、\f、\n、\r、\t和\v,前面加一个(斜杠)。
发布于 2012-08-02 14:41:58
你必须转义引号:
printf("\"");
https://stackoverflow.com/questions/11772291
复制相似问题