如何打印转义字符的字符? [英] How do i print escape characters as characters?
本文介绍了如何打印转义字符的字符?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想打印转义字符作为使用该code字符或字符串:
I'm trying to print escape characters as characters or strings using this code:
while((c = fgetc(fp))!= EOF)
{
if(c == '\0')
{
printf(" \0");
}
else if(c == '\a')
{
printf(" \a");
}
else if(c == '\b')
{
printf(" \b");
}
else if(c == '\f')
{
printf(" \f");
}
else if(c == '\n')
{
printf(" \n");
}
else if(c == '\r')
{
printf(" \r");
}
else if(c == '\t')
{
printf(" \t");
}
else if(c == '\v')
{
printf(" \v");
}
}
但是当我尝试它,它实际打印的转义序列。
but when i try it, it actually prints the escape sequence.
推荐答案
逃离斜杠(使用\\\\一个
),所以他们不会得到跨$ P $特别PTED。您可能还需要使用一个查找表或开关
至少
Escape the slashes (use " \\a"
) so they won't get interpreted specially. Also you might want to use a lookup table or a switch
at least.
switch (c) {
case '\0':
printf(" \\0");
break;
case '\a':
printf(" \\a");
break;
/* And so on. */
}
这篇关于如何打印转义字符的字符?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文