0% found this document useful (0 votes)
56 views2 pages

Just Another Beginner Needs Help With Scrolling Text Up and Down - (

The document discusses code to display a scrolling text interface in C. A user is asking for help modifying the code to read from a file and display around 20 lines that can be scrolled up and down. The provided code displays a hard-coded array of text lines. It redraws the screen to show 3 lines at a time and handles arrow key presses to scroll up and down.

Uploaded by

Yash Rajput
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
56 views2 pages

Just Another Beginner Needs Help With Scrolling Text Up and Down - (

The document discusses code to display a scrolling text interface in C. A user is asking for help modifying the code to read from a file and display around 20 lines that can be scrolled up and down. The provided code displays a hard-coded array of text lines. It redraws the screen to show 3 lines at a time and handles arrow key presses to scroll up and down.

Uploaded by

Yash Rajput
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 2

10/15/2019 Just another beginner needs help with scrolling text up and down :(

CodingFool Thank you guys a lot for your quick replies. First the answer to your question Adak. I mean the real DOS -> MS-
DOS 6.22 ... I forgot to list it.. sorry for that .
Registered User
Join Date: May 2011
Well I think I should use fgets for the beginning(it's the easiest way, isn't it?). But - refering to your reply quzah -
Posts: 5
I don't know how I can realize this. I mean how to redraw the visible part.
I've got questions like for example, should I use an array which can hold up multiple strings or is just one string
variable enough to work with and if I'm using an array then how will I be able to get the right index of it.. and in
the end I just get very confused .

05-11-2011 #6

quzah Ok, say you have a screen that is only 2x2 characters, and our file is 3x3:
ATH0
123
234
Join Date: Oct 2001 345
Posts: 14,826
So we start by showing:

12
23

You press > and now we want to move to the right, so we draw:

23
34

Now I press v so we move down:

34
45

And so on.

Consider using a separate "screen" array and fill that depending on what part they are looking at (what key they
hit, or however you are doing that).

Quzah.

Hope is the first step on the road to disappointment.

05-11-2011 #7

CommonTater
Originally Posted by whiteflags
Banned
Join Date: Aug 2010
For any sufficiently large output, a DOS screen already has a scrollbar...
Location: Ontario Canada
Posts: 9,547
Ummm... no... a CMD window, commonly called a "DOS box" in windows has a scroll bar.
Real MS-DOS wouldn't have the first clue what a scroll bar even is, never mind actually displaying one.
We're talking 25 lines by 80 characters unbuffered, full screen 720 x 400 pixels, here.

if you want to do something fancy then there should be gotoxy() in <conio.h> that prints a character anywhere.

Yes, the conio library with turbo C should help...

05-11-2011 #8

CodingFool Hey guys,


one more time thanks for your replies.
Registered User
I found some code online that I think of it can help me with my problem.
Join Date: May 2011
But I don't know how to change the code so it will read in a file and displays about 20 lines with scrolling
Posts: 5
up/down.
Please can you help me with it? I'm very confused..

Here's the code:


----------------
Code:

1 #include <stdio.h>
2 #include <stdlib.h>
3 #include <conio.h>
4
5 #define length(x) ( sizeof (x) / sizeof *(x) )
6
7 enum {
8 KEY_ESC = 27,
9 ARROW_UP = 256 + 72,
10 ARROW_DOWN = 256 + 80,
11 };
12
13 static const char *text[] = {
14 "Line 1",
15 "Line 2",
16 "Line 3",

https://cboard.cprogramming.com/c-programming/137880-just-another-beginner-needs-help-scrolling-text-up-down.html 2/5
10/15/2019 Just another beginner needs help with scrolling text up and down :(
17 "Line 4",
18 "Line 5",
19 "Line 6"
20 };
21
22 static int get_code ( void )
23 {
24 int ch = getch();
25
26 if ( ch == 0 || ch == 224 )
27 ch = 256 + getch();
28
29 return ch;
30 }
31
32 static void redraw ( int start, int end )
33 {
34 int i;
35
36 clrscr();
37
38 for ( i = start; i < end; i++ )
39 puts ( text[i] );
40 }
41
42 int main ( void )
43 {
44 int start = 0, end = 3;
45 int op = 0;
46
47 while ( redraw ( start, end ), ( op = get_code() ) != KEY_ESC ) {
48 switch ( op ) {
49 case ARROW_UP:
50 if ( start == 0 ) {
51 end = length ( text );
52 start = end - 3;
53 }
54 else {
55 --start;
56 --end;
57 }
58 break;
59 case ARROW_DOWN:
60 if ( end == length ( text ) ) {
61 start = 0;
62 end = start + 3;
63 }
64 else {
65 ++start;
66 ++end;
67 }
68 break;
69 default: break;
70 }
71 }
72
73 return 0;
74 }

05-11-2011 #9

mike65535
I found some code online ...
Registered User
Join Date: Mar 2011
Posts: 278 Strike one.

But I don't know how to change the code...

Swing and a miss, strike two.

Please can you help me with it? I'm very confused..


Yer owt!

C'mon, you've been offered reasonable suggestions as to how to begin coding this (see quzah's post). Lifting code
off the Internet is not "coding".

Take it step by step...

Create a file (notepad works)


Now write code:
Open the file (test for its non-existence)
Read some of it in and display it
Modify some of it and display

and so on

05-11-2011 #10

CommonTater
Originally Posted by mike65535
Banned
https://cboard.cprogramming.com/c-programming/137880-just-another-beginner-needs-help-scrolling-text-up-down.html 3/5

You might also like