Last Updated on 4 weeks by Shaikh Mainul Islam
include
include
include
define MAX 1000
char textStack[MAX];
int top = -1;
char undoStack[MAX];
int undoTop = -1;
// Push character to text stack
void typeChar(char ch) {
if (top < MAX – 1) {
textStack[++top] = ch;
undoStack[++undoTop] = ch; // Save to undo stack
} else {
printf(“Text stack full!\n”);
}
}
// Undo last character
void undo() {
if (undoTop >= 0) {
top–; // Just remove last character from text
undoTop–; // Remove from undo stack
} else {
printf(“Nothing to undo.\n”);
}
}
// Print current text
void printText() {
printf(“Current Text: “);
for (int i = 0; i <= top; i++) {
printf(“%c”, textStack[i]);
}
printf(“\n”);
}
// Main function
int main() {
int choice;
char ch;
while (1) {
printf("\n1. Type Character\n2. Undo\n3. Show Text\n4. Exit\nChoose: ");
scanf("%d", &choice);
switch (choice) {
case 1:
printf("Enter character: ");
scanf(" %c", &ch);
typeChar(ch);
break;
case 2:
undo();
break;
case 3:
printText();
break;
case 4:
exit(0);
default:
printf("Invalid choice.\n");
}
}
return 0;
}