In this problem we simulate a simple text editor. Given two lines of keyboard input texts and commands, output the final text content.
The text editing rules are defined as following:
1.
Normal alphabetical input and whitespace input (abcdefg…. and ‘ ‘) in the first line.
And a series of two special commands started with a backslash(/) character in the second line.
2.
The backspace command which deletes a letter before the cursor (/b)
3.
The navigating command which move the cursor to the right(/r)
4.
The cursor is at the beginning of the text initially.
For example, for the following input:
The quick brown fox jumps over the lazy dog
/b/r/r/r/b
You should first store the "The quick brown fox jumps over the lazy dog" in the input char array and set cursor=0.
Then you can simulate the operation of the text editor.
The size of the text content is less than or equal to 500 characters, and there will be less than or equal to 500 commands when simulating.
The C library function char *gets(char *str) reads a line from stdin and stores it into the string pointed to by str. It stops when either the newline character is read or when the end-of-file is reached, whichever comes first.
Hint:
#include <stdio.h>
#define MAX_SIZE 1001
char content[MAX_SIZE];
char input[MAX_SIZE];
char command[MAX_SIZE];
int main()
{
gets(input);
gets(command);
/* your code here */
printf("%s", content);
return 0;
}
The first line is the text content which should be edited.
The second line is the commands.
There is always a valid command(/b /r) right after the backslash character.
The final text content, and there should be no '\n' at the end of the output.