- fflush(data[j].output);
- fclose(data[j].output);
- delscreen(data[j].screen);
+ for (j = argc - 1; j >= 0; j--) {
+ USING_SCREEN(data[j].screen, close_screen, 0);
+ fprintf(data[j].output, "**Closed\r\n");
+
+ /*
+ * Closing before a delscreen() helps ncurses determine that there
+ * is no valid output buffer, and can remove the setbuf() data.
+ */
+ fflush(data[j].output);
+ fclose(data[j].output);
+ delscreen(data[j].screen);
+ }
+ ExitProgram(EXIT_SUCCESS);