打印到屏幕从C控制台应用程序改写当前行 [英] print to screen from c console application overwriting current line
问题描述
我要覆盖在C控制台程序来实现输出像Linux shell命令顶当前行。如果可能的话,该方法应windows和linux下工作。
I want to overwrite the current line in a c console program to achieve output like in the linux shell command "top". If possible the method should work under windows and linux.
while (i < 100) {
i++;
sprintf(cTmp, "%3d", i);
puts(cTmp);
if ((character = mygetch()) == 'q') {
break;
}
}
我想覆盖previous号在每次迭代中,如果可能的样子,如果用户输入的字符不停顿的循环。如果用户presses关键'Q'的循环,应立即停止。
I would like to overwrite the previous number in each iteration and if possible look if the user entered a character without pausing the loop. If the user presses the key 'q' the loop should stop immediately.
推荐答案
要做到这一点,你需要访问终端。要做到这一点最简单的方法是如 ncurses的库。似乎有一个版本支持Windows以及
To achieve this, you need to access the terminal. The easiest way to do this is with a library like ncurses. There seems to be a version that supports Windows as well.
使用ncurses的,你可以给的坐标为字符串输出,是这样的:
With ncurses, you can give the coordinates for the string to output, like this:
mvprintw(row, col, "%s", text);
这篇关于打印到屏幕从C控制台应用程序改写当前行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!