0% found this document useful (0 votes)
42 views17 pages

Stack-Based Text Editor Implementation

data structure

Uploaded by

nidhikedia2204
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
42 views17 pages

Stack-Based Text Editor Implementation

data structure

Uploaded by

nidhikedia2204
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

C V RAMAN GLOBAL UNIVERSITY

BHUBANESWAR, ODISHA
DATA STRUCTURE
EXPERIENTIAL LEARNING
ON
STACK BASED TEXT EDITOR
Group – 10

Presented By:
Anshuman Mishra – 231020816
Sradha Ram – 2301020808 UNDER THE GUIDANCE OF:

Priyansu Patra –2301020786 SUMANA DE

Prativa Das – 2301020758 BARSHA MISHRA


SWATI SIPRA DAS
Subhasis Purohit – 2301020759
SONALI MAHAPATRA
Rekha Kumari – 2301020783
Monideepa Kar – 2301020784
Chiraj Ballava Mohanty – 2301020785

1
ACKNOWLEDGMENT:

We would like to thank our Professor-in-charge, Miss


Sumana De for guiding us throughout this assignment. She
was there to help us in every step of the way, and her
motivation helped us complete this assignment successfully.
We thank all the teachers who helped us by providing the
necessary and vital equipment, without which we would not
have been able to work effectively on this assignment.

2
Content
1. Introduction
2. What is text editor?
3. Text editor operations
4. Advantages of using a stack
5. Code
6. Code Explanation
7. Output
8. Future work
9. Conclusion
10. References

3
INTRODUCTION

In this report, we'll explore implementing a text


editor using a stack-based approach. By leveraging
stacks, we can efficiently manage text editing
operations like undo and redo. Let's dive in!

4
WHAT IS TEXT EDITOR?

A text editor is a software application used for


creating, editing, and manipulating plain text files.
Examples of text editors include Notepad, Sublime
Text, Vim, Emacs, and Visual Studio Code.

5
TEXT EDITOR OPERATIONS

1. Inserting Text: Adding new text at the cursor


position.
2. Deleting Text: Removing text characters or
blocks from the document.
3. Selecting Text: Highlighting specific portions of
the text for editing or formatting.
4. Copying/Cutting and Pasting Text: Duplicating
or moving selected text to another location within
the document.
5. Undo/Redo: Reversing or redoing recent edits
made to the document.

6
ADVANTAGES OF USING A STACK FOR
TEXT EDITING

1. *Efficient data management*


2. * Efficient management of functions*
3. *Control over memory*
4. *Smart memory management*
5. *Not easily corrupted*

7
CODE
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#define MAX_LINE_LENGTH 100
typedef struct Node
{
char text[MAX_LINE_LENGTH + 1];
struct Node *next;
} Node;
Node *head = NULL;
void push(const char *line)
{
Node *new_node = (Node *)malloc(sizeof(Node));
if (new_node == NULL)
{
printf("Memory allocation error\n");
return;
}
strncpy(new_node->text, line, MAX_LINE_LENGTH);
new_node->text[MAX_LINE_LENGTH] = '\0';
new_node->next = head;
head = new_node;
}
char *pop()
8
{
if (head == NULL)
{
printf("Stack empty\n");
return NULL;
}
Node *temp = head
char *popped_line = (char *)malloc((MAX_LINE_LENGTH + 1) *
sizeof(char));
if (popped_line == NULL)
{
printf("Memory allocation error\n");
return NULL;
}
strncpy(popped_line, temp->text, MAX_LINE_LENGTH);
popped_line[MAX_LINE_LENGTH] = '\0';
head = head->next;
free(temp);
return popped_line;
}
void display()
{
Node *current = head;
while (current != NULL)
{

9
printf("%s\n", current->text);
current = current->next;
}
}
int main()
{
char line[MAX_LINE_LENGTH + 1];
while (1)
{
printf("Enter a command (i: insert, d: delete, p: print, q: quit): ");
scanf(" %c", &line[0]);
switch (line[0])
{
case 'i':
printf("Enter line to insert: ");
getchar(); // consume the newline character left in the input
buffer
fgets(line, MAX_LINE_LENGTH + 1, stdin);
line[strcspn(line, "\n")] = '\0';
push(line);
break;
case 'd':;
char *popped = pop();
if (popped != NULL)
{

10
printf("Deleted line: %s\n", popped);
free(popped);
}
break;
case 'p':
display();
break;
case 'q':
printf("Exiting...\n");
exit(0);
default:
printf("Invalid command\n");
}
}
return 0;}

Function Definitions:
• initialize: Initializes the stack by setting its top
index to -1.
• isFull: Checks if the stack is full.
• isEmpty: Checks if the stack is empty.
• push: Pushes an element onto the stack.
• pop: Pops an element from the stack.

11
• Traversal: Traverses to all elements of the
stack.
• display: Print all the element of the stack.
• Exit: Terminates from the program
Main Function:
• Initializes a stack.
• Enters a loop to repeatedly display a menu and
perform operations based on user input.
• Allows the user to insert strings into the stack,
delete elements, traverse the stack, convert
elements to uppercase or lowercase, or exit the
program.
The code provides a basic interface for interacting
with a stack, allowing users to insert strings,
manipulate stack elements, and convert case.

12
OUTPUT

13
14
FUTURE WORK
Some potential future enhancements for
stack-based text editor are :
1. *Advanced Text Manipulation Features:* - Implement more
sophisticated text manipulation functionalities such as search and
replace, text formatting options, and syntax highlighting.

2. *Collaborative Editing Support:* - Integrate real-time


collaborative editing capabilities to allow multiple users to work on
the same document simultaneously, with proper synchronization using
the stack data structure.

3. *Customization Options:* - Provide users with the ability to


customize the editor's appearance, key bindings, and functionality to
better suit their preferences and workflow.

4. *Integration with Version Control Systems:*


- Enable seamless integration with version control systems like Git,
allowing users to easily track changes, revert to previous versions, and
manage collaborative projects more effectively.

5. *Cross-Platform Compatibility:*
- Develop versions of the text editor for various platforms including
desktop (Windows, macOS, Linux) and mobile (iOS, Android), ensuring
a consistent user experience across different devices.

15
CONCLUSION

Implementing a stack-based text editor


allows for efficient undo and redo
functionality. By leveraging stacks, users
can easily navigate through their editing
history, enhancing the overall user
experience.
This approach offers simplicity, efficient
memory usage, and fast undo/redo
operations, making it a valuable tool for
text editing.

16
REFERENCES

1. Basics of File Handling in C


GeeksforGeeks →
[Link]
c/

2. fgets() and gets() in C language - GeeksforGeeks→


[Link]
c/

3. Explain the END OF FILE (EOF) with a C Program →


[Link]
file-eof-in-c

4. C Tutorial - Deleting a Record from a Binary Fil


>>CodingUnitProgramming Tutorials →
[Link]
programming/175239-delete-record-random-access-
[Link]

17

You might also like