Source Code File 10-02_sub2

10-02_sub2.c

#include <ncurses.h>

int main()
{
    WINDOW *quartersub;
    int slines,scols,sposy,sposx;
    
    initscr();
    
    /* subwindow location math */
    slines = LINES/2;
    scols = COLS/2;
    sposy = (LINES-slines)/2;
    sposx = (COLS-scols)/2;
        
    /* create subwindow */
    quartersub=subwin(stdscr,slines,scols,sposy,sposx);
    if( quartersub==NULL)
    {
        endwin();
        puts("Unable to create subwindow");
        return(1);
    }
    
    /* add text */
    addstr("This is the standard screen");
    waddstr(quartersub,"This is the subwindow");
    refresh();
    getch();
    
    endwin();
    return(0);
}

Output Screenshot

Notes

* The screenshot above shows the bare minimum. You get bonus points if you colored or boxed the windows to show them separate.

* This source code file is referenced as 10-02_colorsub.c in the book.