10. Display one special character as the cursor using ascii code \"@\" at the po
ID: 3533016 • Letter: 1
Question
10. Display one special character as the cursor using ascii code "@" at the position of mytext[0][0].
11. Replace Step 5. "Change all your texts to upper case" with "Display 20 lines from the current line on the screen". The current line is where you start displaying lines of texts. It's original value is zero, but it can be modified by the cursor moving out of the 20-line frame.
12. You can use "j" to move the cursor down one line, "k" up one line, "h" left one character, and "l" right one character. Of course, if there is no place to move left, right, up, or down, the cursor just stays. Because you moved the cursor, you need to clear the screen and then display again with the new cursor position. system("clear"); will be able to clear the screen.
You can use the real "vi" and see how it works. As you can see, I have showed my implementation in class already. Hope you can do it yourself now.
Extending on the previous homework, let's have more functions in our editor:
1. You can use "x" to delete a single character at the special character, which we call the "cursor";
2. You can use "dd" to delete a single line, so that all lines behind the deleted line move up accordingly;
3. You can use "i" to start inserting a string at the cursor. Also, when you type "enter" while you are inserting, the rest of the string behind the current cursor will go to the next line, and all the lines behind will move down as well, and your insertion will continue at the beginning of next line. You can use "esc", the escape key, to stop insertion, so that your system comes back into where before you started insertion. You may want to stop insertion if the current line is full of characters. <?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" />
Explanation / Answer
#include "vi.h"
void deleteline (char mytext[][STRLEN], cp_t cursor, int nl)
{
int i=0;
int j=0;
for (i = cursor.x; i< nl; i++)
{
for ( j=0; j<80; j++)
{
mytext[i][j] = mytext[i+1][j];
}
}
}
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.