偶做的简单行编辑程序

作者:袖梨 2022-07-02

这是我的行编辑程序,各位指点指.

#include
#include
#define STACK_INIT_SIZE 100
#define MAXSIZE    50
#define  INCREMENT 10
#define  OVERFLOW  -2
#define  ERROR     -1
#define  OK         0

typedef struct
{
 int *base;
 int *top;
 int StackSize;
}SqStack,*PStack;

void InitStack(PStack S);
void DestroyStack(PStack S);
void ClearStack(PStack S);
int GetTop(PStack S,int *e);
void Push(PStack S,int e);
int Pop(PStack S);

void InitStack(PStack S)
{
 if(!(S->base = (int *)malloc(STACK_INIT_SIZE *sizeof(int))))
  exit(OVERFLOW);
 S->top = S->base;
 S->StackSize  = STACK_INIT_SIZE;
 return;

}

void DestroyStack(PStack S)
{
 free(S->base);
 S->top = S->base;
 return;
}

void ClearStack(PStack S)
{
 S->top = S->base;
 return;
}

int  GetTop(PStack S,int *e)
{
 if(S->top == S->base)
  return ERROR;
 *e = *(S->top - 1);
 return OK;

}
void Push(PStack S,int e)
{
 if(S->top - S->base >=S->StackSize)
 {
  S->base = (int *)realloc(S->base,(STACK_INIT_SIZE + INCREMENT) *sizeof(int));
 if(!S->base)
  exit(OVERFLOW);
    S->top  = S->base + S->StackSize ;
 S->StackSize  = S->StackSize  + INCREMENT;

 }
 *S->top ++  = e;
 return;
  
}

int Pop(PStack S)
{
 if(S->top - S->base ==0)
  return ERROR;
      S->top --;
 return OK;
}

int main()
{
 SqStack S;
 char ch;
 FILE *fp;
 char Array[MAXSIZE];
 int *p;
 int i ;


 InitStack(&S);
 printf("please enter the context:n");
 ch = getchar();
 while(ch != '!')
 {
  while(ch != '!' && ch != 'n')
  {<

相关文章

精彩推荐