我刚开始用Ncurses编程,但当我启动这个程序时,我得到了"Segmentation fault(core dump)"。当我调用函数post_menu(…)时会发生这种情况。
char *mainMenu_choices[] = {
"Say Hello!",
"Close",
};
ITEM **mainMenu_items = (ITEM **)NULL;
MENU *mainMenu = (MENU *)NULL;
int mainMenu_choices_COUNT, i = 0;
int mainMenu_status = TRUE;
ITEM *mainMenu_selectedItem = (ITEM *)NULL;
int draw_mainMenu()
{
mainMenu_status = TRUE;
mainMenu_choices_COUNT = ARRAY_SIZE(mainMenu_choices);
mainMenu_items = (ITEM **)calloc(mainMenu_choices_COUNT + 1, sizeof(ITEM *));
for(i = 0; i < mainMenu_choices_COUNT; i = i + 1)
{
mainMenu_items = new_item(mainMenu_choices[i], mainMenu_choices[i]);
}
mainMenu_items[mainMenu_choices_COUNT] = (ITEM *)NULL;
mainMenu = new_menu((ITEM **)mainMenu_items);
post_menu(mainMenu);
refresh();
return 0;
}
提前谢谢。附言:很抱歉我没有发表评论。
您没有在循环中正确填充mainMenu_items
。
你在做
mainMenu_items = ...
但你可能是指
mainMenu_items[i] = ...