ncurses LINES 和 COLS 为 0?
ncurses LINES and COLS are 0?
我正在尝试学习 ncurses 但遇到了一个奇怪的错误。 LINES 和 COLS 似乎设置为 0,或者设置为不是 int
:
的值
我的代码的相关部分:
#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);
这输出:
1556162876
0
0
Floating point exception
我做错了什么?
根据 ncurses 文档:
The integer variables LINES and COLS are defined in <curses.h> and will
be filled in by initscr with the size of the screen.
所以在调用 initscr
之前,它们可能只是 0。
是的,正如 Chris Dodd 之前提到的,在调用 initscr()
之前,它们的值将为 0。但是在调用 initscr()
之后,它们的值将为分别是屏幕的行和列 stdscr
。 getmaxyx(stdscr, row, col)
也可以将这些值分配给整数 row
和 col
.
我正在尝试学习 ncurses 但遇到了一个奇怪的错误。 LINES 和 COLS 似乎设置为 0,或者设置为不是 int
:
我的代码的相关部分:
#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);
这输出:
1556162876
0
0
Floating point exception
我做错了什么?
根据 ncurses 文档:
The integer variables LINES and COLS are defined in <curses.h> and will be filled in by initscr with the size of the screen.
所以在调用 initscr
之前,它们可能只是 0。
是的,正如 Chris Dodd 之前提到的,在调用 initscr()
之前,它们的值将为 0。但是在调用 initscr()
之后,它们的值将为分别是屏幕的行和列 stdscr
。 getmaxyx(stdscr, row, col)
也可以将这些值分配给整数 row
和 col
.