c - getyx 返回 -1 -1

标签 c macos curses

#include <stdio.h>
#include <curses.h>

int main () {

int y, x;
getyx( curscr, y, x);

printf("x=%i, y=%i", x, y);
return 0; }

gcc a.c -lcurses -o a

x=-1, y=-1

为什么?

最佳答案

也许您应该在尝试使用 curses 之前调用 initscr();

#include <stdio.h>
#include <curses.h>

int main (void)
{
    int y = 0, x = 0;

    initscr();
    getyx(curscr, y, x);
    printw("x = %d, y = %d", x, y);
    refresh();
    getchar();
    endwin();
    return 0;
}

您会发现至少阅读编程库的一些文档是值得投入时间的,例如http://tldp.org/HOWTO/NCURSES-Programming-HOWTO/

关于c - getyx 返回 -1 -1,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3382306/

相关文章:

ios - 使用 CoreText 和 CTFontDescriptor 设置字体粗细

objective-c - AutoLayout中如何取较大的高度作为父高度

windows - OSX 和 Windows 上的文本之间存在 1 像素垂直差异

python - 属性 BOLD 似乎在我的诅咒中不起作用

c - 将文本从txt文件解析为C中的多维数组

c -/lib/libmatrix.a : file not recognized: File format not recognized collect2: ld returned 1 exit status

c - 如何使用 scanf() 获取任意数量的整数?

c - 功能结束时出现段错误

ruby - 通过 telnet/ssh 实现 nCurses