1

I'm using the library ncurses, and when I try to call wprintw(), and then do a wrefresh on the right window, it doesn't print anything.

#include <stdio.h>
#include <stdlib.h>
#include <ncurses.h>

int main()
{
    WINDOW *winTest; //The window
    int rows, cols; //Rows and colums in the terminal

    initscr(); //Starting NCurses
    raw(); //Calling 'getch()' doesn't wait for '\n' 
    noecho(); //Doesn't print what's written by user
    curs_set(0); //Doesn't display the cursor

    getmaxyx(stdscr, rows, cols); //How many rows and colums in stdscr (the terminal)

    winTest = newwin(10, 10, rows/2, cols/2); //Creates a square WINDOW at the center of the terminal

    mvwprintw(winTest, 0, 0, "Test"); //Prints "Test" on the created window

    wrefresh(winTest); //Refreshes so what's done is displayed
    getch(); //Pause

    delwin(winTest); //Free the memory for winTest
    endwin(); //Ends NCurses
    return 0;
}

When I execute this, nothing is displayed.

I'm on Ubuntu 14.04 LTS, I compile with gcc:

gcc -g -Wall -Werror -Wpedantic -Wextra -Wformat -o test.exe test.c -lncurses

and I execute in the gnome-terminal.

Dan Lowe
  • 51,713
  • 20
  • 123
  • 112
Aizen
  • 155
  • 10
  • Seeing you hide all the compiler errors is not a good sign. Remove this stuff: `-Wall -Werror -Wpedantic -Wextra -Wformat` the compiler might tell you something important. – Tony Ruth Jan 02 '16 at 22:00
  • @TonyRuth: you're aware that these flags enable *additional* warnings (and also make them fatal)? – Christoph Jan 02 '16 at 22:02
  • @TonyRuth ehem... that's enabling all compiler errors, not hiding them. – fuz Jan 02 '16 at 22:02
  • Ah, you're right, sorry. – Tony Ruth Jan 02 '16 at 22:03
  • I replaced the second pause, `getch()` with my own pause function: `scanf("%*s");` and then it displayed test in the middle like it was supposed to. I think what was happening is it went through both pauses in one go so that you never saw the "Test" because it was deleted as fast as it was created. – Tony Ruth Jan 02 '16 at 22:11
  • 1
    Possible duplicate of [NCurses Refresh](http://stackoverflow.com/questions/3808626/ncurses-refresh) – Ruud Helderman Jan 02 '16 at 22:23

2 Answers2

2

As explained here, you should replace:

getch();

by:

wgetch(winTest);
Community
  • 1
  • 1
Ruud Helderman
  • 10,563
  • 1
  • 26
  • 45
0

I replaced the second pause, getch() with my own pause function: scanf("%*s"); and then it displayed test in the middle like it was supposed to. I think what was happening is it went through both pauses in one go so that you never saw the "Test" because it was deleted as fast as it was created. – Tony Ruth

Thanks to Tony Ruth, who answered my question. Even if I still don't understand why getch() erases what's written, replacing it with scanf("%*s") works fine !

PS: Don't know how to tell this issue is solved :/

EDIT : You can also call 'wgetch(aWindow)' on whatever window, and every windows will be corectly displayed :) (Thank to Ruud, who told it)

Aizen
  • 155
  • 10