Question
Write a C++ program that displays the contents of a file in curses mode. If the contents of the file are too big to fit
Write a C++ program that displays the contents of a file in curses mode. If the contents of the file are too big to fit on the screen, then your program needs to allow the user to scroll through the output using the up and down arrow keys.
Running program
Assuming your executable is called program1, you should be able to run your program as follows to open and display the contents of a file called filename.txt
$ ./program1 filename.txt
For this program, you will need to use the following prototype for main:
int main(const int argc, const char * argv []);
code below is what i have so far, which is suppose to display filename.txt and be able to scroll the output with the arrow keys. But my code does not let the filename.txt to display nor allow to scroll up and down.
Please help!
#include
using namespace std;
WINDOW *create_newwin(int height, int width); void destroy_win(WINDOW *local_win);
int main (const int argc, char *argv[] ) {
WINDOW *my_win; int width, height; int ch;
initscr(); cbreak(); keypad(stdscr, TRUE);
height = 3; width = 10; refresh(); my_win = create_newwin(height, width);
while((ch = getch()) != KEY_F(1)) { switch(ch) { case KEY_UP: destroy_win(my_win); my_win = create_newwin(height-, width); break; case KEY_DOWN: destroy_win(my_win); my_win = create_newwin(height++ , width); break; } }
if ( argc != 2 ) // argc should be 2 for correct execution // We print argv[0] assuming it is the program name cout<<"usage: "<< argv[0] <<"
endwin();
return 0;
}
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started