如何正确使用curses/调试一个简单的c程序
我正在努力学习如何使用诅咒来处理即将到来的作业的输入。 我得到了一个名为testcurses.c的c程序,其中包含以下代码如何正确使用curses/调试一个简单的c程序,c,ncurses,curses,C,Ncurses,Curses,我正在努力学习如何使用诅咒来处理即将到来的作业的输入。 我得到了一个名为testcurses.c的c程序,其中包含以下代码 #include <curses.h> #include <stdio.h> #include <stdlib.h> // brief example of using curses. // man 3 ncurses for introductory man page, and man 3 function name // for m
#include <curses.h>
#include <stdio.h>
#include <stdlib.h>
// brief example of using curses.
// man 3 ncurses for introductory man page, and man 3 function name
// for more information on that function.
void setup_curses();
void unset_curses();
int main()
{
setup_curses();
move(5, 10);
printw("Press any key to start.");
refresh();
int c = getch();
nodelay(stdscr, true);
erase();
move(5, 10);
printw("Press arrow keys, 'q' to quit.");
refresh();
c = getch();
while(1)
{
if (c != ERR)
{
// in asn3, won't need to do any printing to screen.
// instead, will rotate figure on left or right arrow keys, and
// initiate thrust when space bar is pressed.
erase();
move(5,10);
printw("Press arrow keys, 'q' to quit.");
move(6, 10);
if (c == KEY_DOWN)
printw("down key pressed");
else if (c == KEY_LEFT)
printw("left key pressed");
else if (c == KEY_RIGHT)
printw("right key pressed");
else if (c == KEY_UP)
printw("up key pressed");
else if (c == 'q')
break;
refresh();
}
c = getch();
}
// must do this or else Terminal will be unusable
// (if there are problems, it's not that big a deal though ... just
// close the Terminal, and open a new one.)
unset_curses();
exit(EXIT_SUCCESS);
}
void setup_curses()
{
// use return values. see man pages. likely just useful for error
// checking (NULL or non-NULL, at least for init_scr)
initscr();
cbreak();
noecho();
// needed for cursor keys (even though says keypad)
keypad(stdscr, true);
}
void unset_curses()
{
keypad(stdscr, false);
nodelay(stdscr, false);
nocbreak();
echo();
endwin();
}
我不明白这是在告诉我什么,文件之间的差异是什么导致了这种混乱。请帮忙
我应该告诉您一些关于发送到sketchpad的以下命令的信息
drawSegment x y x1 y1在画板窗口中从(x,y)->(x1,y1)绘制一条线
擦除段x y x1 y1擦除该行。首先,您的行指针从不指向任何真实的对象。这可能会导致堆芯转储 您可以执行的最小编辑修复:-
line_item _line;
line_item *line;
然后在主循环之前执行以下操作:-
line = &_line;
听起来你想在gdb中运行你的测试程序。这样,当你得到一个内核转储时,你可以1)得到一个回溯,2)可能确定崩溃时相关变量的值。我用gdb运行它,它给了我以下额外的行程序接收信号SIGABRT,中止。0x00007FF7609425位于../nptl/sysdeps/unix/sysv/linux/raise.c:64../nptl/sysdeps/unix/sysv/linux/raise.c.的文件或目录中:没有这样的文件或目录。(gdb)当gdb捕捉到崩溃时,您可以使用
bt
(backtrace)命令查看调用链。使用up
命令转到您的功能。然后,您可以检查变量以查看可能的错误。请阅读。啊,是的,我的不好-但是当我让它指向行项目的一个元素时,我仍然得到相同的错误。
line_item _line;
line_item *line;
line = &_line;