Hi , iam trying to develop a simple text editor on Turbo C , that will accept values from the keyboard and print on the screen . I want a scrolling function . when i entered th data and press enter button it will come to the next line . I think when i press enter on the last line , transfer the last content of the array to previous one and blank the last line ,and so on , then user seems it a scrolling eefect .


how to transfer array = array[i-1] , and put it ina while loop , and reprint the array on screen


-------------------------------------------------
1
2
3
4
5 - <--- press enter here on screen

--------------------------------------------------

-------------------------------------------------
2
3
4
5
6 - <--- now the cursor is here, and when user press Enter key

------------------------------------
3
4
5
6
7- <----- now cursor is here........

and i want to continue it as infinite . plz help me ....

i have all cases in my program Enter,Left,Right,Del,Back space....
Please help me to convert a good text editor in dos.....

u got the concept . idon't know to explain it....please help me....

Recommended Answers

All 11 Replies

I believe there are 2 sub cases when the user presses Enter:

1) If the cursor position is above (less than) the bottom row of the current screen (usually 25, but may be 43 or 50), then the cursor just moves to the next row down, and to the first column of that row. No rows are appearing at the bottom, or disappearing from the top of the screen.

2) If the cursor position is on the bottom row of the screen, then everything on the page should move upward, and a blank row should be added to the bottom of the screen. Again, the cursor is moved to the (new) bottom row, and to the first column of that row.

You may move the rows upward 2 ways:

1) by having an absolute array # of rows for your screen. (1-25 maybe)
2) by having a "windowed" array of rows for your screen. Here, the top row of the array (etc.), will change. It may start with 1, but when you press enter, the top row becomes 2, and the bottom row becomes 26, see?

Which way do you want to move the rows upward, and what specific problem are you having trying to do it?

for(r = 1; r < 26; r++)
   for(c = 1; c < 81; c++)
      array[r-1][c] = array[r][c];

Where r = row, and c = column, and row 0 and column 0 are not used, which works well with the screen, btw.

Is that helpful?

Thanks . But i don't get the full points , and one doubt . Consider in my program, i set the last row as 4 . Then i need to reprint the array after 4th row . I think then only it will generates a scrolling effect . Then how to reprint the array on the same gotoxy positions.. is it possible with a while loop . My array is a char array. and if i press enter on 4 th row .


imagine my screen length is to hold only 4 rows at a time ...


rows
----
1 ------> TOM
2 ----- > DICK
3 ------ > HARRY
4 -------> TEENA - <----- Cursor


when i type TEENA and press enter , i want the result like this..in screen

rows
----
2 ------> DICK
3 ------> HARRY
4 -------> TEENA
5 -------> - <------ Cursor .....


okay ... plz confirm it on any text editor ....... actully, that i want here with arrays ....

Yes, the text on the screen will only scroll when you have the cursor on the bottom row of the screen, and press Enter. It doesn't matter where on the bottom row, just anywhere, on the bottom row.

And I showed you code to help do that. (the two for loops)

Your array should be a two dimension array, like screen[row][col]. Row will equal 4 in your case, and col will equal the width of your program's screen, in char's.

If the user presses the delete key, you move all the other char's over 1 column to the left. Of course, that effects all the rows below it, as well, so they also shift over 1 column to the left. The char on column 1 goes up one row on the screen, to the last column in the higher row on the screen.

If the user presses the space bar, you move all the char's to it's right, and below it on the screen. All these char's move one column to the right. Char's at the last column, need to go down to the next row. All the char's below it will be shifted in this way.

case ENTER:          
			// when press enter ,row incriments
			Row ++ ;     
			
			// Index is set to 0, to locate first column
			Index = 0;   
				
			gotoxy( Index+2 , Row+2 ) ;    // the cursor will now point on (col,row) ..
                        
                        if(Row >= 10)
	                {

	                for(Row = 1; Row < 10; Row ++)
			{
			for(Index = 1; Index < 10; Index++ )
			{
			
                        Data[ Row - 1 ][ Index ] = Data[ Row ][ Index ];

			gotoxy( Index + 2, Row + 2 );
			
			printf("%c",Data[Row][Index]);
			
                        }
                        
                        }


						   
                        }
						  
                        break;

but it not printing ... help me . This is my code that i used in my enter case.....consider here MaxRow = 10 .... correct me......

I don't see any differentiation between the cursor being on the last line, and the cursor being on some other line of the screen.

It is impossible for me to tell what's wrong without the full code, so I can run it and see what's happening as it runs.

Normally, like the forum editor here, all the char's to the right of the cursor are moved down to the next lower row on the screen, when Enter is pressed. That area will then be filled with blank spaces, the end of the row. All the rows below the cursor will be pushed down on the screen, by one row.

So your logic has to handle both the char's to the right of the cursor when Enter is pressed, and also handle all the rows of char's which are below the cursor. Lastly, it must move the cursor itself, down one row, and over to column 1.

Now, after the char's have been moved in the screen array, each char will need to be printed, in it's new location.

It's always helpful if you indent your code, properly. It makes it much easier to spot logic problems, particularly in nested loops. Also, I would *not* use row 0 or column 0. When you're dealing with a screen, which has no row 0 or column 0 on it, that will always goof you up. Use row 1 and column 1 and then it's simple, since gotoxy(1, 1) ), for example, makes perfect sense.

ok, thanks. But plz help me in reprint the array on the same loaction in the screen . Plz iam anewbie ...plz help me to understand ,,, plz specify a example with small code..plz

ok, thanks. But plz help me in reprint the array on the same loaction in the screen . Plz iam anewbie ...plz help me to understand ,,, plz specify a example with small code..plz

Posting up my editor would do you no good. I was a student when I wrote it, and it's in another language.

You can reprint the array via code like this:

for(row = 1; row < 5; row++)   {
   gotoxy(1, row);
   for(col = 1; col < 20; col++)
      putchar(screen[row][col]);
   putchar('\n');
}

This is done after you've made your changes in the screen array, of course.

This is also off the cuff, I didn't try to run the above. I believe it's OK, however.

I'm having a lot of trouble trying to understand what the real problem is that you're stuck on. You're going to have to post your whole program so I can run it, and see what is wrong or right with it.

hi Adak .Thanks for ur information.

then only one doubt. How to reprint the array on screen using a foor loop . I have an array Data[20][80] , and my variables are " Cols , Rows " . My screen length is small to hold only 4 rows . When i press enter on 4th row , i need to reprint the 4th element to 2nd element on screen ,right?. And now row increases to 5. The cursor will blink on 5 th row. And when i press enter on 5 th row , i need to reprint the screen from 5th element to 3 th element. then cursor is in 6th elemnt . then what i do on 8th row ?. How to accomplish this using a for loop ..


row is increasing every time i press enter .

and when row is 8
and whrn row is 12
and so on ... ... ..

hi.... some body help me .. how to to generate a scrolling effect in screen by reprinting the array every time after last row in the screen ( 24th row ).......... Please give me an idea in simple way ...... please..............


how to continuously reprint the array on the screen when i press enter

When you press enter on 4th row, the letters on the 4th row, should be moved up to the 3rd row. The cursor will still be on the 4th row (because that is your bottom row), and that 4th row will now be all blank spaces ' '.

I believe that a "stationary" display array, rather than a "windowed" display, will be much easier to work with.

Adak

What compiler are you using?

Does it have a "conio.h" file? Does it have a "window" or similar command to create a text mode window?

Because as I'm typing in your program's window, the letters don't "wrap" to the next line, they just go right off the window! :(

If you have a window command, use it, and include the "conio.h" header file, if you have it. It includes commands to shortcut this type of program: clreol (clears all text from cursor to the end of the line), etc.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.