I'm trying to make a simple ncurses program to display a box with messages. Im following this link and it works well. The problem that I'm having is that if I put the whole code in a function and call it in a loop, the initialisation is having an error. As far as I know, if I called endwin()
at the end of the function, there shouldn't be any problem calling the initscr()
again. Am I missing a function to enable the initscr()
to be called again?
This is the code:
#include <stdio.h>
#include <unistd.h>
#include <stdlib.h>
#include <curses.h>
int call()
{
WINDOW *mainwin, *childwin;
int ch;
if ((mainwin = initscr()) == NULL) {
fprintf(stderr, "Error initialising ncurses.\n");
exit(EXIT_FAILURE);
}
noecho();
curs_set(FALSE);
keypad(mainwin, TRUE);
mvaddstr(childwin, 1, 6, "Warning! Press q to exit");
mvaddstr(childwin, 2, 15, "{ OK }");
refresh();
while( (ch = getch()) != 'q') {
refresh();
}
delwin(mainwin);
endwin();
refresh();
return EXIT_SUCCESS;
}
int main()
{
int i;
for (i=0;i<10;i++) {
call();
}
return 0;
}
EDIT: I've put the header file. Change the code to be more simpler