简体   繁体   中英

ncurses basic example - in debug i get: “Error opening terminal: unknown.”

doing some basic examples on ncurses libreries, I get some issues.

Actually, I don't get what I expect (message printed), and going in debug, from eclipse, I get (in console area) "Error opening terminal: unknown."

Follows code:

#include <unistd.h>
#include <stdlib.h>
#include <ncurses.h>


int main() {

    initscr();

    move(5,15);
    printw("%s", "Hello world!");
    refresh();

    endwin();
    exit(EXIT_SUCCESS);
}

Compiler options, as provided in Eclipse console at "Build project" command:

make all 
Building file: ../source/Curses_01.c
Invoking: GCC C Compiler
gcc -Incurses -O0 -g3 -Wall -c -fmessage-length=0 -MMD -MP -MF"source/Curses_01.d"     -MT"source/Curses_01.d" -o"source/Curses_01.o" "../source/Curses_01.c"
Finished building: ../source/Curses_01.c

Building target: Curses_01
Invoking: GCC C Linker
gcc  -o"Curses_01"  ./source/Curses_01.o   -lcurses
Finished building target: Curses_01

Thanks everybody in advance!

You do get the string printed. The problem is that the program exits immediately. This will clear the screen and restore it to its previous state. This happens very fast, of course, so you don't get to see anything.

The solution is to wait for a keypress before exiting. You can do this with getch() :

/* ... */
refresh();
getch();
endwin();
exit(EXIT_SUCCESS);

The Eclipse problem arises due to the terminal presented by Eclipse to the application. NCurses doesn't recognize it. I don't use Eclipse, so I don't know exactly how to do this, but you should search for some setting that allows you to run the application inside a full terminal (like in xterm, Konsole, Gnome Terminal, etc.)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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