eclipse ncurses and xterm, unknown characters printed

1.1k views Asked by At

I faced with Error opening terminal: unknown. with ncurses and Eclipse Luna.

So installed xterm and add TERM=xterm in Run/Debug Configurations > Environment.

Now, when I run following simple "Hello World" app, some strange characters printed in the Eclipse console:

enter image description here

Code:

#include <stdio.h>
#include <ncurses.h>

int main() {
    initscr();                 /* Start curses mode     */
    printw("Hello World !!!"); /* Print Hello World    */
    refresh();                 /* Print it on to the real screen */
    getch();                   /* Wait for user input */
    endwin();                  /* End curses mode    */

    return 1;
}

What are these characters? And how to remove them?

1

There are 1 answers

0
n. m. could be an AI On BEST ANSWER

These characters are what initscr() outputs to do its job.

A terminal knows not to show these characters and interpret them in a special way. Since the Eclipse console is not a terminal, it has not a faintest idea.

If you want your program to work in both terminals and non-terminals, you need to check whether your standard output is a terminal, and avoid using ncurses-specific functions if it is not. See man isatty.

If you only need your program to work in terminals, just don't use Eclipse console. See this question and its answer for set-up instructions.