gpt4 book ai didi

C scr_restore 函数不工作

转载 作者:太空宇宙 更新时间:2023-11-04 04:38:48 25 4
gpt4 key购买 nike

大家好,我正在编写这个程序,它“可以”恢复由 scr_dump(); 创建的转储文件。转储部分正在工作,但恢复部分没有。这样做的目的是复制标准屏幕上的任何内容并将其复制到一个文件中,然后通过再次调用该文件,它应该绘制最初存在的内容。

          int firstLoop = 0;

initscr();
while (exitCounter != 1)
{

if (firstLoop == 0)
{
printw("Testing 123");
scr_dump("test");
clear();
firstLoop = 1;
exitCounter = 1;
}
}


scr_restore("test");
doupdate();
refresh();


getch();

endwin();
}

最佳答案

您应该在 printw() 调用之后添加对 refresh() 的调用,否则您将转储空白屏幕。

使用这段代码:

#include <curses.h>

int main(void) {
initscr();
noecho();

printw("Testing 123");
refresh();

scr_dump("test");
clear();

getch();

scr_restore("test");
doupdate();
refresh();

getch();

endwin();

return 0;
}

您应该会看到一个空白屏幕,然后在按下某个键后,会看到您的“Testing 123” 消息。 scr_dump()scr_restore() 都可能失败,因此显然您应该检查返回值。

关于C scr_restore 函数不工作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28508809/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com