Source Code File 10-01_sub1
10-01_sub1.c
#include <ncurses.h>
int main()
{
WINDOW *sub;
initscr();
/* create subwindow on stdscr */
sub = subwin(stdscr,LINES-2,COLS-2,1,1);
if( sub==NULL)
{
endwin();
puts("Unable to create subwindow");
return 1;
}
/* draw a box around stdscr */
box(stdscr,0,0);
/* put text to the subwindow */
waddstr(sub,"I'm in a subwindow.\n");
refresh();
getch();
endwin();
return 0;
}
Output Screenshot

Notes
* This output shows a benefit of subwindows I describe in the book: Subwindow sub provides for a one-character offset inside the box around the standard screen. This way you can write text to the subwindow without clobbering the box around the parent window.
Copyright © 1997-2025 by QPBC.
All rights reserved
