【文件属性】:
文件名称:编程模拟简单行编辑器(c/c++)
文件大小:2KB
文件格式:CPP
更新时间:2016-01-17 12:12:44
行编辑器 栈
#include
#include
#include
#define INILEN 100
#define ADDlEN 20
typedef struct
{
char *base;
char *top;
int stacksize;
}stack;
stack bjs;
void Init(stack *s)
{
s->base=(char *)malloc(INILEN*sizeof(char));
s->top=s->base;
s->stacksize=INILEN;
}
void push(stack *s,char e)
{
if((s->top-s->base)>=(s->stacksize))
{
s->base=(char *)realloc(s->base,(s->stacksize+ADDlEN)*sizeof(char));
s->top=s->base+s->stacksize;
}
*s->top=e;
s->top++;
}
char pop(stack *s)
{
char e;
if(s->top==s->base) return 0;
s->top--;
e=*s->top;
return e;
}
void destroy(stack *s)
{
char *de;
de=s->base;
free(de);
s->base=s->top=NULL;
s->stacksize=0;
}
void fun1()
{
if(bjs.base!=bjs.top)
{
printf("文本:\n");
char a;
char *p;
p=bjs.base;
for(p;p