I am trying to learn the PDcurses package in C but i keep getting this problem:
LINES value must be >= 2 and <= 1252: got -1
initscr(): Unable to create SP
My code:
#include <curses.h>
#include <stdlib.h>
#include <string.h>
int main()
{
FILE *lsofFile_p = popen("hostname", "r");
if (!lsofFile_p)
{
return -1;
}
int row,col;
char buffer[1024];
char *line_p = fgets(buffer, sizeof(buffer), lsofFile_p);
pclose(lsofFile_p);
initscr(); /* start the curses mode */
start_color();
init_pair(1,COLOR_GREEN,COLOR_BLACK);
init_pair(2,COLOR_BLUE,COLOR_BLACK);
getmaxyx(stdscr,row,col); /* get the number of rows and columns */
attron(COLOR_PAIR(1));
mvprintw(row/2,(col-strlen(line_p)-26)/2,"Your computer name is : ");
attroff(COLOR_PAIR(1));
attron(COLOR_PAIR(2)|A_BOLD);
printw("%s",line_p);
/* print the message at the center of the screen */
attroff(COLOR_PAIR(2)|A_BOLD);
wrefresh(stdscr);
system("pause");
endwin();
}
This works fine in Linux with ncurses instead of curses. If i simply try printing Hello world, it works too. So I have no idea where it is going wrong or how to fix it.
I am using MinGW gcc for compiling and I've got PDCurses installed from there too. I am running the code on Windows Terminal.
The error message indicates that PDcurses was unable to get the screen size from the Windows console. This may mean that it failed to figure out what type of terminal you are using (Windows console? Something else?). You may be able to get past this by setting the
LINESenvironment variable to the correct value for your screen.PDCurses tries to get this info by calling the windows function GetConsoleScreenBufferInfoEx in kernel32.dll, which should be pretty independent of what you're using compiler/terminal/whatnot, as long as you do have some kind of terminal window (not running headless)