This project is a line editor developed in C that allows you to open, read, modify, and save text files. The program supports CRUD (Create, Read, Update, Delete) operations on lines of text and individual words, along with search and navigation features. The editor uses a linked list data structure to store both lines and words, making it efficient for operations like insertion and deletion.
- File Handling: Open, read, and write to files in different modes (
r+orw+). - Buffer Storage: Stores lines in a linked list for ease of insertion and deletion.
- Search Functionality: Search for a word in the file and get the cursor position (line number and word position).
- CRUD Operations:
- Insert a new line at the cursor position.
- Insert a word at the cursor position in a specific line.
- Update a word with another word.
- Delete a line or a word in a line.
- Undo/Redo: Supports undo and redo functionality for the last three operations.
- A C compiler (e.g., GCC)
- Standard C libraries (stdio.h, stdlib.h, string.h)
-
Clone the Repository If you are using Git, clone the repository:
git clone https://github.com/Mr-Yash-beldar/Line-Editor.git cd Line-Editor -
Compile the Program Use the following command to compile the program:
gcc -o lineeditor line_editor.cpp
-
Run the Program
You can run the program from the command line using different arguments to specify the file you want to edit.
without Argument (Creates or Read file.txt by default):
./line_editor
-
One Argument (Create a new file in the current directory or read it if present already):
./line_editor testfile.txt
This will create a new file called
testfile.txtin the current directory or open it if it already exists. -
Two Arguments (Open an existing file or create a new file in the current directory):
./line_editor yash.txt
-
Three Arguments (Open an existing file or create a new file in a specific directory):
./line_editor yashodip.txt foldername
-
More than 3 Arguments (Error handling):
Error: Too many arguments. Usage: ./line_editor <filename> [directory]
-
-
Command Line Operations: After opening a file, you can interact with the file through different commands:
-
Search: Search for a word in the file and return the line number and word position.
-
Insert Line: Insert a new line at the cursor position.
-
Insert Word: Insert a new word at the cursor position within a line.
-
Update Word: Replace an existing word with another word.
-
Delete Line: Delete a line at the cursor position.
-
Delete Word: Delete a word at the cursor position within a line.
-
Undo: Undo the last 3 operations.
-
Redo: Redo the last 3 undone operations.
-
line_editor.c # Main program file with logic
README.md # Project documentation-
Opening a file for the first time:
./lineeditor myfile.txt
This will open
myfile.txtor create it if it doesn't exist. -
Inserting a line at a specific position:
- After the file is opened, the cursor is at the first line.
- Insert a new line:
Insert a new line at line 1: "This is a new line."
-
Searching for a word:
-
Search for the word "line" in the file:
Search for the word 'line'
This will return the line number and the position of the word in that line.
-
-
Update a word:
- Update the word "line" to "sentence":
Update 'line' to 'sentence' in line 1
- Update the word "line" to "sentence":
-
Undo the last operation:
Undo the last operation
-
Redo the last undone operation:
Redo the last undone operation
-
If you get an error about too many arguments:
- Ensure you are using a maximum of 3 arguments (filename and optional directory).
-
If the file does not open or cannot be read:
- Check if the file exists and is accessible with the given permissions.
This project is licensed under the MIT License - see the LICENSE file for details.