c - 使用 ncurses 打印字符失败

标签 c ncurses

我正在使用 XUBUNTU 16.04 和 Geany。 我开始测试库 ncurses。但我无法显示字符。当我运行程序时出现一个窗口,但字符“a”和“*”没有出现。

这是我的代码:

#include <ncurses.h>
void line(char ch, int n)
{
 int i;
 for( i = 1; i<=n; i++ )
      addch(ch);
 }

 int main()
 {
  clear();
  line("a", 50);
  line("*", 8);
  return 0;
 }

最佳答案

man curs_refresh:

The refresh and wrefresh routines (or wnoutrefresh and doupdate) must be called to get actual output to the terminal, as other routines merely manipulate data structures.

因此您的程序缺少 refresh();

看起来您还缺少初始化/清理,即在程序开始时调用 initscr() 并在程序结束时调用 endwin()

关于c - 使用 ncurses 打印字符失败,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47499400/

相关文章:

压缩二维数组

在 Linux 中更改进程名称

c - linux下如何用mingw使用splint

python - curses.wrapper() 在背景/前景序列之后弄乱终端

c - 将 ncurses 窗口保持在前台

c - 当我创建守护进程时,fopen() 似乎不起作用

c - 跨文件基于 const int 构造成员数组大小

c - 使用命令行参数读取文本文件不起作用

Swift 包管理器无法编译通过 Homebrew 安装的 ncurses

Ncurses 可滚动文本阅读器