Display lines after pressing N and P

T

TOSHIBA2005

Hi all,
I'm trying to write a program that should display a text file on screen
15 lines at a time. It display the next 15 lines after typing N, or
previous 15 lines after typing P. I'm pretty newbie to programming.
Could someone tell me how we can do that? Thanks very much in advance.
 
J

Joe Estock

Hi all,
I'm trying to write a program that should display a text file on screen
15 lines at a time. It display the next 15 lines after typing N, or
previous 15 lines after typing P. I'm pretty newbie to programming.
Could someone tell me how we can do that? Thanks very much in advance.

You could do this one of several ways. You could use a singly linked
list, doubly linked list, pointer to a location in the file, etc. I
would simply read the file into a doubly linked list 30 lines at a time
(15 * 2). For a "quick n dirty" doubly linked list for the job:

struct buffer
{
struct buffer *first;

char *line;

struct buffer *last;
};

As far as the implementation goes you're on your own ;) If after you've
attempted this and are still stuck feel free to post other questions
here along with the code and anyone here would be more than happy to
help you out further. Or perhaps someone else has a better idea for
accomplishing what you are attempting to do.

<OT>
The "more" command in Linux would be a prime source to look at for ideas
on how you could write such a program. It most likely uses ncurses as
well, however you should get the general idea.
</OT>

Joe
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
474,170
Messages
2,570,927
Members
47,469
Latest member
benny001

Latest Threads

Top