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.)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With