Tookmund
Tookmund

Reputation: 103

ncurses LINES and COLS are 0?

I am trying to learn ncurses but have hit an odd error. LINES and COLS appear to be set to 0, or else to something that is not an int:

relevant parts of my code:

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

[...]

printf("%d\n%d\n%d\n",rand(),LINES,COLS);
blk[i].pos[0] = (int)(rand()/LINES);
blk[i].pos[1] = (int)(rand()/COLS);

This outputs:

1556162876
0
0
Floating point exception

What am I doing wrong?

Upvotes: 3

Views: 6548

Answers (2)

Eyong Kevin Enowanyo
Eyong Kevin Enowanyo

Reputation: 1032

Yes as previously mentioned by Chris Dodd, prior to calling initscr(), their values will be 0. However after calling initscr(), their value will be the rows and column of the screen stdscr respectively. getmaxyx(stdscr, row, col) can also assign these values to the integers row and col.

Upvotes: 0

Chris Dodd
Chris Dodd

Reputation: 126388

Per the ncurses documentation:

The integer variables LINES and COLS are defined in <curses.h> and will be filled in by initscr with the size of the screen.

So prior to calling initscr, they are probably just 0.

Upvotes: 3

Related Questions