/*行编辑程序*/
/*利用栈实现的*/
#include "stdio.h"
#include "stdlib.h"
#define SIS 100 /*初始大小*/
#define SI 10 /*增量大小*/
#define OVERFLOW 0
#define TRUE 1
#define FALSE 0
typedef struct{
char *base;
char *top;
char stacksize;
}Sqstack;
char Initstack(Sqstack *s)
{
s->base=(char *)malloc(SIS*sizeof(char));
s->top=s->base;
s->stacksize=SIS;
}
char Push(Sqstack *s, char e)
{
if(s->top-s->base>=s->stacksize)
{
s->base=(char *)realloc(s->base,(SIS+SI)*sizeof(char));
if(!s->base) exit(OVERFLOW);
s->top=s->base+s->stacksize;
s->stacksize+=SI;
}
*s->top++=e;
}
char StackEmpty(Sqstack s)
{
if(s.top==s.base)
return TRUE;
else
return FALSE;
}
char Pop(Sqstack *s, char *e)
{
if(s->top==s->base) return FALSE;
*e=*(--s->top);
}
char GetTop(Sqstack s)
{
char e;
if(s.top==s.base) return FALSE;
e=*(s.top-1);
return(e);
}
char Clearstack(Sqstack *s)
{
while(s->top!=s->base)
s->top=s->base;
}
char Destroystack(Sqstack *s)
{
while(s->top!=s->base)
{
s->top--;
free(s->top);
}
}
void LineEdit()
{
Sqstack *s;
char ch,c;
s=(Sqstack *)malloc(sizeof(Sqstack));
Initstack(s);
ch=getchar();
while(ch!=EOF&&ch!='\n')
{
switch(ch)
{
case '#': Pop(s,&c); break;
case '@': Clearstack(s); break;
default : Push(s,ch); break;
}
ch=getchar();
}
while(s->top!=s->base)
{
Pop(s,&c);
printf("%c",c);
}
Destroystack(s);
}
main()
{
printf("Input data :\n");
LineEdit();
}
/*行编辑程序*/
/*利用栈实现的*/
#include "stdio.h"
#include "stdlib.h"
#define SIS 100 /*初始大小*/
#define SI 10 /*增量大小*/
#define OVERFLOW 0
#define TRUE 1
#define FALSE 0
typedef struct{
char *base;
char *top;
char stacksize;
}Sqstack;
char Initstack(Sqstack *s)
{
s->base=(char *)malloc(SIS*sizeof(char));
s->top=s->base;
s->stacksize=SIS;
}
char Push(Sqstack *s, char e)
{
if(s->top-s->base>=s->stacksize)
{
s->base=(char *)realloc(s->base,(SIS+SI)*sizeof(char));
if(!s->base) exit(OVERFLOW);
s->top=s->base+s->stacksize;
s->stacksize+=SI;
}
*s->top++=e;
}
char StackEmpty(Sqstack s)
{
if(s.top==s.base)
return TRUE;
else
return FALSE;
}
char Pop(Sqstack *s, char *e)
{
if(s->top==s->base) return FALSE;
*e=*(--s->top);
}
char GetTop(Sqstack s)
{
char e;
if(s.top==s.base) return FALSE;
e=*(s.top-1);
return(e);
}
char Clearstack(Sqstack *s)
{
while(s->top!=s->base)
s->top=s->base;
}
char Destroystack(Sqstack *s)
{
while(s->top!=s->base)
{
s->top--;
free(s->top);
}
}
void LineEdit()
{
Sqstack *s;
char ch,c;
s=(Sqstack *)malloc(sizeof(Sqstack));
Initstack(s);
ch=getchar();
while(ch!=EOF&&ch!='\n')
{
switch(ch)
{
case '#': Pop(s,&c); break;
case '@': Clearstack(s); break;
default : Push(s,ch); break;
}
ch=getchar();
}
while(s->top!=s->base)
{
Pop(s,&c);
printf("%c",c);
}
Destroystack(s);
}
main()
{
printf("Input data :\n");
LineEdit();
}