在一个循环做initscr的()导致初始化错误 [英] doing initscr() in a loop causes error initialisation

查看:235
本文介绍了在一个循环做initscr的()导致初始化错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想作一个简单的ncurses程序,以显示与消息框。 IM按照此链接和它工作得很好。我时遇到的问题是,如果我把整个code在一个函数并调用它在一个循环中,初始化是有一个错误。据我知道,如果我叫 endwin()在函数结束时,不应该有任何问题,调用 initscr的() 一次。我缺少一个功能,使 initscr的()再次调用?

I'm trying to make a simple ncurses program to display a box with messages. Im following this link and it works well. The problem that I'm having is that if I put the whole code in a function and call it in a loop, the initialisation is having an error. As far as I know, if I called endwin() at the end of the function, there shouldn't be any problem calling the initscr() again. Am I missing a function to enable the initscr() to be called again?

这是code:

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

int call()
{
    WINDOW *mainwin, *childwin;
    int ch;

    if ((mainwin = initscr()) == NULL) {
            fprintf(stderr, "Error initialising ncurses.\n");
            exit(EXIT_FAILURE);
    }

    noecho();
    curs_set(FALSE);

    keypad(mainwin, TRUE);

    mvaddstr(childwin, 1, 6, "Warning! Press q to exit");
    mvaddstr(childwin, 2, 15, "{ OK }");
    refresh();
    while( (ch = getch()) != 'q') {
            refresh();
    }

    delwin(mainwin);
    endwin();
    refresh();

    return EXIT_SUCCESS;
}

int main()
{
    int i;

    for (i=0;i<10;i++) {
            call();
    }

    return 0;
}

编辑:我已经把头文件。更改code更简单

I've put the header file. Change the code to be more simpler

推荐答案

该示例程序不叫 initscr的不止一个。但是,它不显示的#include 线是(需要编译),所以也许它不是它实际上运行该程序。

The sample program does not call initscr more than one. However, it does not show the #include lines either (necessary to compile), so perhaps it is not the program which was actually run.

关于主叫 initscr的的问题(一次或一次以上),至少有两种可能性:

Regarding a problem calling initscr (once or more than once), there are at least two possibilities:


  • 您使用的是一些其他实现诅咒的(例如,一个Unix的,如HPUX)。如在X / Open 指出,可移植程序不能调用initscr的不止一次

  • TERM 变量没有被设置为可使用的值。像往常一样,href=\"http://invisible-island.net/ncurses/man/curs_initscr.3x.html\" rel=\"nofollow\">手册页的解释函数做什么,以及为什么它可能会失败。

  • you are using some other implementation of curses (e.g., a Unix one such as HPUX). As noted in X/Open, portable programs must not call initscr more than once.
  • the TERM variable is not set to a usable value. As usual, the manual page explains what the function does, and why it might fail.

这篇关于在一个循环做initscr的()导致初始化错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆