Ncurses No Output

2019-07-19 08:55发布

问题:

  • Platform: Linux 3.2.0 x86 (Debian Wheezy)
  • Compiler: GCC 4.7.2 (Debian 4.7.2-5)

I am writing a program that requires advanced terminal control that is provided by ncurses but I cannot get my program to print anything to stdscr. For example if I compiled the following code I would not see "Testing.. Testing" on the screen. I have used ncurses before and I have never encountered such a problem. I do not know if this is relevant or not but I am running a fresh install of Debian (I literally installed it a couple of hours ago).

#include <ncurses.h>

int main()
{
    initscr();
    printw("Testing... Testing");
    refresh();
    return;
}

Also the above progam was compiled with,

gcc --all-warnings --extra-warnings -std=c11 filename.c -lncurses

回答1:

If you want to see the text, maybe you should keep the program running when you're printing it.

#include <ncurses.h>

int main()
{
    initscr();
    printw("Testing... Testing");
    refresh();
    getch(); // Wait the user input in order to keep the program active and showing text.
    endwin(); // Terminate the window to clean all memory allocations.
    return;
}

You can get more informations on the ncurses "hello world": http://tldp.org/HOWTO/NCURSES-Programming-HOWTO/helloworld.html



标签: c ncurses