我怎么能抹去用C印在控制台当前行?我工作在Linux系统上 [英] How can I erase the current line printed on console in C ? I am working on a linux system

查看:179
本文介绍了我怎么能抹去用C印在控制台当前行?我工作在Linux系统上的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我怎么能抹去印在C控制台上的当前行?我工作在Linux系统上

How can I erase the current line printed on the console in C? I am working on a linux system

例如 -

printf("hello");
printf("bye");

我要的地方打招呼的在同一行打印再见。

I want to print bye on the same line in place of hello.

再见

推荐答案

您可以使用 VT100逃生codeS 的。大多数终端,包括xterm的,是VT100知道。对于删除一条线,这是 ^ [[2K 。在C这给:

You can use VT100 escape codes. Most terminals, including xterm, are VT100 aware. For erasing a line, this is ^[[2K. In C this gives:

printf("%c[2K", 27);

这篇关于我怎么能抹去用C印在控制台当前行?我工作在Linux系统上的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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