简体   繁体   English

从C中的控制台输出获取先前打印的行

[英]Get previously printed line from console output in C

I'm making a very simple console text editor. 我正在制作一个非常简单的控制台文本编辑器。 In order to move the cursor to the end of the previous line when I backspace at the beginning of a line, I need to read an already printed line from the console, then get its length. 为了在行首退格时将光标移动到前一行的末尾,我需要从控制台读取已经打印的行,然后获取其长度。 How would I go about making this work? 我将如何进行这项工作?

There is no way to do this using scanf() and printf() ; 无法使用scanf()printf()做到这一点; the program would need to keep track of what it prints. 该程序将需要跟踪其打印内容。 However, it is also impossible to edit previously printed screen lines using only the standard I/O functions - in order to do that, you'd need to use eg ncurses . 但是,也不可能仅使用标准I / O功能来编辑先前打印的屏幕行-为此,您需要使用例如ncurses

将要打印的每个元素存储在编辑器中的char数组中,因为您可能必须从头开始或在中间返回,而不仅仅是一行。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM