简体   繁体   English

ncurses printw 不会将任何内容打印到 window

[英]ncurses printw wont print anything into window

I am trying to create a window and print some text to it using ncurses but I am just getting a blank screen.我正在尝试创建一个 window 并使用 ncurses 向其打印一些文本,但我只是得到一个空白屏幕。 I believe that printw is not working because I was able to open a working window with the same functions in the same order in a different program.我相信 printw 不起作用,因为我能够在不同的程序中以相同的顺序打开具有相同功能的工作 window。

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

char string[] = "string";

int main(void)
{
    system("clear");
    int c;
    initscr();
    curs_set(0);
    noecho();
    keypad(stdscr, TRUE);
    cbreak();
    WINDOW *game_window;
    game_window=newwin(40,40,1,1);
    int num=0, highs=0;
    while (TRUE) {
        clear();
        printw("\t%s\n", string);
        printw("\tScore: %d    High Score: %d\n", num, highs);
        sleep(1);
        break;
    }
    endwin();
    printf("done\n");
    return 0;
}

since you are printing this (I believe this is your intention) in game_window, use wprintw instead of printw :因为你在 game_window 中打印这个(我相信这是你的意图),所以使用wprintw而不是printw

wprintw(game_window, "\t%s\n", string);
wprintw(game_window, "\tScore: %d    High Score: %d\n", num, highs);

also, don't forget to that ncurses requires you to refresh windows:另外,不要忘记 ncurses 要求您刷新windows:

refresh(); // main screen
wrefresh(game_window); // game_window window

That should help;那应该有帮助; Here's the whole code so you know where I placed above ;)这是整个代码,所以你知道我放在上面的位置;)

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

char string[] = "string";

int main(void)
{
    system("clear");
    int c;
    initscr();
    curs_set(0);
    noecho();
    keypad(stdscr, TRUE);
    cbreak();
    WINDOW *game_window;
    game_window=newwin(40,40,1,1);
    int num=0, highs=0;
    while (TRUE) {
        clear();
        wprintw(game_window, "\t%s\n", string);
        wprintw(game_window, "\tScore: %d    High Score: %d\n", num, highs);
        refresh();
        wrefresh(game_window);
        sleep(1);
        break;
    }
    endwin();
    printf("done\n");
    return 0;
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM