C语言 如何在 C 中打印斜杠(/ 或 \)?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/29796371/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How to print out a slash (/ or \) in C?
提问by George Cavalevu
I know this is a very silly and simple question but I've been trying to print out an image of a robot that should output this:
我知道这是一个非常愚蠢和简单的问题,但我一直在尝试打印出应该输出以下内容的机器人图像:
+----------+
| |
| /\ /\ |
| \/ \/ |
| |
| [-=-=-] |
+----------+
The part I'm stuck on is printing out the eyes. originally I coded:
我坚持的部分是打印眼睛。最初我编码:
printf("| /\ /\ |");
printf("| \/ \/ |");
but an error showed, so I remembered that you need to double slash so:
但是显示了一个错误,所以我记得你需要双斜线,所以:
printf("| \/\ \/\ |");
printf("| \\/ \\/ |");
but an error saying implicit declaration of function printf is showing even after that?! I don't understand the error. Can someone explain how to fix this please?
但是即使在那之后仍然显示函数 printf 的隐式声明的错误?!我不明白这个错误。有人可以解释一下如何解决这个问题吗?
回答by Benjy Kessler
You don't need to escape forward slash.
你不需要逃避正斜杠。
This works for me:
这对我有用:
#include <stdio.h>
int main()
{
printf("| /\ /\ |");
printf("| \/ \/ |");
return 0;
}
回答by Nils
You have to use \ before backslash. Its separate the character.Like this
您必须在反斜杠之前使用 \。它分开了字符。像这样
printf("| /\ /\ |\n");
printf("| \/ \/ |");

