C- Ncurses, Window not displaying / printing

c, ncurses

Solution

You forgot to call refresh.

Basically, you did call refresh on your newly create window, but you forgot to refresh the parent window, so it never redrew.

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

int main()
{
    WINDOW* my_win;
    int height = 10;
    int width = 40;
    int srtheight = 1;
    int srtwidth = 1;
    initscr();
    printw("first"); // added for relative positioning
    refresh();  //  need to draw the root window
                //  without this, apparently the children never draw
    my_win = newwin(height, width, 5, 5);
    box(my_win, 0, 0);  // added for easy viewing
    mvwprintw(my_win, height/2,width/2,"First line");
    wrefresh(my_win);
    getch();
    delwin(my_win);
    endwin();
    return 0;
}   

gives the windows as you expected.

Problem

Ive tried looking for a solution, i just don't know why the window is not displaying. The code is fairly simple and straight forward. Why is this the case? I asked a similar question before but know one seems to have been able to provide the right answer, so I made it a bit simpilar and only included the important stuff. ``` #include <ncurses.h> #include <stdio.h> #include <stdlib.h> int main() { initscr(); WINDOW* win; int height = 10; int width = 40; int srtheight = 1; int srtwidth = 0; win = newwin(height, width, srtheight ,srtwidth); mvwprintw(win, height/2,width/2,"First line"); wrefresh(win); getch(); delwin(win); endwin(); return 0; } ```

Original source