One tip: Don't use array for holding the contents. It won't work.
Another tip: Gap or list.
One tip: Don't use array for holding the contents. It won't work.
Another tip: Gap or list.
That won't be very practical. If you delete the first character in a line, you have to shift other 79 characters back one place, and when the user enters a new character in the beginning of the line, you have to shift them back. IF you don't use some kind of delay in the changes to the actual buffer, or use another buffer containing a copy of current line or something somewhere else. Still that doesn't work well when user enters completely new line. You have to shoft all the lines further in the buffer.
I still say gap buffer or list. First one is traditionally used in emacsen and the latter is used very well in fancy eds also known as vis and are easy to implement.
So I'm doing some tests here, but I'm stuck. How will the computer know if one of the arrow keys is pressed?
I'm thinking something like that:
if(string=="user presses right arrow")
{
x++;
gotoxy(x,y);
}
but what will the code for "user presses right arrow be? I'm thinking of putting the ASCII code for the arrow keys but I can't find anything.
Just for testing I'm using a string and not an array or something else.
That depends on how you're getting input. If you're doing a keyboard poll, you'd have to check whether right-arrow is in a key-down state. If you're getting signals, then you're "strange" keys have special values that depend on what library you're using.
Hmmm....I never heard my professor tell us anything about this stuff, it can't be that difficult. Right now I'm using stdlib,stdio and screentUtils libraries.
You're not going to get arrow keys (or control-whatever key combinations) using stdio. stdio only gives you line-buffered input -- your program doesn't see anything until the user presses Enter, and then all it sees is the final result in one rush.
If you want to be able to type arrow keys and actually have it work, then you'll need to get closer to the hardware.
Arrays can work OK, but I wouldn't use 10,000 lines for this. Three or four times the number of chars you show on a single page of your editor, should be fine.
@fronty: yes, you shift char's - no, it's not professional - yes, it will do for a beginner's exercise.
I think using linked list containing every line on a node inside some very simple malloc'd dynamic array implementation won't be very hard, even simpler with hard coded maximum line length like in your implementation. This will make creating and destroying lines work better and won't be hard to implement. Similar situation with gap buffer, it isn't really far from simple array implementation, but makes operations work better. It won't be hard for a beginner if he know basic data structures.
Hi guys! I m obviously a co-student of fink and i have the same assignment... We could use a character arrow but not any dynamic solution since we haven't taught anything about pointers(we only use them -but without really knowing- in loading and saving text(fopen,etc).
Mainly it's an explanation about the assignment data, but i also haven't done anything... I generally imagine it as a character arrow in which there will be some "if"(for example if the user hits backspace-8 in ascii table- go to the previous place). My most important problem is how to make the status bar...
Do you mind if I ask how far you are into this course?