C 中空格的转义序列是什么?
我正在编写一个程序来计算空格、制表符和换行符。我记得制表符和换行符的转义序列是什么,但是空格呢? <代码>\b?或者那个是退格键?
I'm writing a program to count blanks, tabs, and newlines. I remember what the escape sequence for tabs and newlines are, but what about blanks? \b
? Or is that backspace?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
你的意思是像
“a b”
中的“空白”?这是一个空格:' '
。这是转义序列列表
You mean "blanks" like in
"a b"
? That's a space:' '
.Here's a list of escape sequences for reference.
如果要检查字符是否为空格,可以使用
中的isspace()
函数。在默认的 C 语言环境中,它检查空格、制表符、换页符、换行符、回车符和垂直制表符。If you want to check if a character is whitespace, you can use the
isspace()
function from<ctype.h>
. In the default C locale, it checks for space, tab, form feed, newline, carriage return and vertical tab.空格就是
' '
,在十六进制中它存储为 20,相当于 32 的整数。例如:检查整数 32。同样:
检查整数 10,因为
\n< /code> 是十六进制的
0A
,即整数 10。以下是其余最常见的转义序列及其十六进制和整数对应项:
Space is simply
' '
, in hex it is stored as 20, which is the integer equivalent of 32. For example:Checks for integer 32. Likewise:
Checks for integer 10 since
\n
is0A
in hex, which is the integer 10.Here are the rest of the most common escape sequences and their hex and integer counterparts:
\b
是退格键 (ASCII 0x8)。您不需要对常规空格(ASCII 0x20)进行转义。您可以只使用' '
。\b
is backspace (ASCII 0x8). You don't need an escape for regular space (ASCII 0x20). You can just use' '
.'\b' 是退格键,您实际上不需要空格的转义序列,因为 ' ' 就可以了。
'\b' is backspace, and you don't really need an escape sequence for blanks as ' ' will do just fine.