-2

Got this issue on termux (Android Linux terminal emulator) . Here it is the ENTIRE code:

#include <ncurses.h>    
int main() {
    initscr();
    getch();
    endwin();
}

I then compiled using this line:

g++ -lncurses prog.cpp

The package is ncurses-dev 6.1.20180331 (latest version) P.S. even with refresh() it doesn't work.

HDJEMAI
  • 9,436
  • 46
  • 67
  • 93
  • 3
    And where does it crash when running it in the debugger? What does the stacktrace look like? What did you learn by inspecting the program state in the stackframes around the crash? – Jesper Juhl Apr 15 '18 at 18:32

1 Answers1

0

The program must end if initscr returns null.

If initscr returns null, then it is not safe to execute further code in the program.

WINDOW * mainwin;

if ( (mainwin = initscr()) == NULL ) {
    /* Error handling here */
    exit(EXIT_FAILURE);
}

Reference:

http://www.paulgriffiths.net/program/c/srcs/curin1src.html

A B
  • 4,068
  • 1
  • 20
  • 23
  • how does this deal with segfault? Is "exit" the same as "return 0"? And how do I handle the error? Just by raising them? – Zeus213 Apr 15 '18 at 18:42
  • If initscr returns NULL, then it is possible the segfault occurred at any point afterwards - possibly either in getch or at another location. As soon as you know that initscr returns null, print an error to the user of the program and return a failure code. exit is a standard C function. You can pass an integer to the exit function to indicate the program exit status. – A B Apr 15 '18 at 18:45
  • I checked - EXIT_FAILURE is the standard integer passed to the exit function to indicate the program exited with a failure status. – A B Apr 15 '18 at 18:47
  • Thank you for having checked. Anyway, I'm pretty sure the problem is getch() after many attempts, by erasing one line at a time, and at the end I got just these 5, so the problem must be getch. – Zeus213 Apr 15 '18 at 18:49