Implement stack in array implementation using the following code : #include #include #include char data[100][100]; // 2d char array to store all the input data int count = 0,u_count=0; void undo() { if(count>0) { count --; u_count ++; } } void redo() { if(count<99 && u_count > 0) { count++; u_count --; } } void print() { for(int i =0;i "); gets(inp); if(!strcmp(inp,"undo")) undo(); else if(!strcmp(inp,"redo")) redo(); else if(!strcmp(inp,"print")) print(); else if(!strcmp(inp,"save")) save(); else if(!strcmp(inp,"quit")) exit(0);
Implement stack in array implementation using the following code :
#include<stdio.h>
#include<string.h>
#include<stdlib.h>
char data[100][100]; // 2d char array to store all the input data
int count = 0,u_count=0;
void undo() { if(count>0) { count --; u_count ++; } }
void redo() { if(count<99 && u_count > 0) { count++; u_count --; } }
void print() { for(int i =0;i<count;i++) printf("%s\n",data[i]); }
save() { FILE *filePointer; filePointer = fopen("output.txt","w");
for(int i=0;i<count;i++)
fprintf(filePointer,"%s\n",data[i]); }
void add(char *str) { strcpy(data[count],str); count++; }
int main() { while(1) {
char inp[100];
printf("MyCommand > ");
gets(inp);
if(!strcmp(inp,"undo")) undo();
else if(!strcmp(inp,"redo")) redo();
else if(!strcmp(inp,"print")) print();
else if(!strcmp(inp,"save")) save();
else if(!strcmp(inp,"quit")) exit(0);
else add(inp); } }
Step by step
Solved in 2 steps