In this problem we simulate a simple text editor. Given a series of keyboard input, output the final text content.
The text editing rules are defined as following:
1. Normal alphabetical input and whitespace input (abcdefg…. and ‘ ‘) directly write after the cursor of the text content.
And four special commands started with a backslash(/) character
2. The backspace command which deletes a letter before the cursor (/backspace)
3. The newline command which creates a new line after the cursor (/newline)
4. The two navigating commands which move the cursor (/left /right)
The size of the text content is fixed to 500 characters, and the text content of testcases will not exceed 500 characters when simulating.
Hint:
#include#define MAX_SIZE 500 char content[MAX_SIZE]; char input[MAX_SIZE]; int main() { fgets(input, MAX_SIZE, stdin); /* your code here */ printf("%s", content); return 0; }
The keyboard input sequence.
There is always a valid command(/backspace /newline /left /right) right after the backslash character.
There is no newline character at the end
The final text content.