printf(“ \033c”)是什么意思? [英] What does printf("\033c" ) mean?

查看:1254
本文介绍了printf(“ \033c”)是什么意思?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在寻找一种在关闭程序后重置 Unix终端窗口的方法,偶然发现 printf( \033c); ,但我听不懂。我去了 man console_codes ,由于我对Unix c编程不太了解,所以它不是很有帮助。

I was looking for a way to "reset" my Unix terminal window after closing my program, and stumbled upon printf("\033c" ); which works perfectly, but I just can't understand it. I went to man console_codes and since I'm somewhat inexperienced with Unix c programming, it wasn't very helpful.

有人可以解释 printf( \033c); 吗?

推荐答案

以C开头的零开头的数字是 八进制 数字。以8为底​​的数字。

In C numbers starting with a leading zero are octal numbers. Numbers in base 8.

其作用是打印由八进制数字 33 表示的字符,后跟'c'

What it does is print the character represented by octal number 33 followed by a 'c'.

ASCII编码八进制数 33 ESC

有了这些知识,我们可以找到例如终端控制序列的前缀。 此VT100控制序列参考 VT100 是旧的哑巴终端,并且被大多数现代终端程序所模仿)。使用VT100参考,我们可以在终端设置部分找到< ESC> c ,在此处将其记录为

With that knowledge searching for terminal control sequences we can find e.g. this VT100 control sequence reference (VT100 was an old "dumb" terminal, and is emulated by most modern terminal programs). Using the VT100 reference we find <ESC>c in the terminal setup section, where it's documented as


重置设备< ESC> c

Reset Device <ESC>c

全部重置终端设置为默认设置。

Reset all terminal settings to default.






ESC \x1b 来打印c $ c>字符(仍然假定为ASCII编码)。无法在常量字符串文字中使用十进制数字,只能使用八进制和十六进制。


The ESC character could also be printed using "\x1b" (still assuming ASCII encoding). There is no way to use decimal numbers in constant string literals, only octal and hexadecimal.

然而 (如由 chux的推荐)序列 \x1bc 不会 \033c 相同。这是因为 0x1bc 是有效的十六进制数字,并且编译器在解析此类序列时为 greedy 。它将打印由值 0x1bc 表示的字符,我不知道它可能是什么(取决于我认为的语言环境和终端设置,可能会被当作Unicode来使用。字符)。

However (as noted by the commend by chux) the sequence "\x1bc" will not do the same as "\033c". That's because 0x1bc is a valid hexadecimal number, and the compiler is greedy when it parses such sequences. It will print the character represented by the value 0x1bc instead, and I have no idea what it might be (depends on locale and terminal settings I suppose, might be prited as a Unicode character).

这篇关于printf(“ \033c”)是什么意思?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆