# Include <stdio. h>
# Include <string. h>
# Include <conio. h>
# Include <stdlib. h>
# Define STACK_INIT_SIZE 50
# Define OK 1
# Define TRUE 1
# Define FALSE 0
# Define ERROR 0
# Define ESC 27
Typedef char ElemType;
Typedef struct STACK/* define STACK type */
{
ElemType * base;
ElemType * top;
Int stacksize;
Int length;
} SqStack, * Stack;
Typedef int Status;
Void InitStack (Stack * S)/* initialize Stack */
{
* S = (SqStack *) malloc (sizeof (SqStack ));
(* S)-> base = (ElemType *) malloc (STACK_INIT_SIZE * sizeof (ElemType ));
If (! (* S)-> base) exit (-1 );
(* S)-> top = (* S)-> base;
(* S)-> stacksize = STACK_INIT_SIZE;
(* S)-> length = 0;
}
Status DestroyStack (Stack * S)/* destroy Stack */
{
Free (* S)-> base );
Free (* S ));
Return OK;
}
Void ClearStack (Stack * S)/* empty Stack */
{
(* S)-> top = (* S)-> base;
(* S)-> length = 0;
}
Status StackEmpty (SqStack S)/* determine whether the stack is empty */
{
If (S. top = S. base) return TRUE;
Else
Return FALSE;
}
Void Push (Stack * S, ElemType e)/* Push data to Stack */
{
If (* S)-> top-(* S)-> base> = (* S)-> stacksize)
{
(* S)-> base = (ElemType *) realloc (* S)-> base,
(* S)-> stacksize + 10) * sizeof (ElemType ));
If (! (* S)-> base) exit (-1 );
(* S)-> top = (* S)-> base + (* S)-> stacksize;
(* S)-> stacksize + = 10;
}
* (* S)-> top ++) = e;
++ (* S)-> length;
}
Status Pop (Stack * S, ElemType * e)/* Delete the top element of the Stack */
{
If (* S)-> top = (* S)-> base) return ERROR;
* E = * (* S)-> top-1 );
-- (* S)-> length;
(* S)-> top --;
Return OK;
}
Void LineEdit ()
{Stack S;
FILE * fp;
Char ch, c, a [50];
Int I, B;
InitStack (& S);/* construct an empty stack for the buffer zone */
Fp = fopen ("wenjian. c", "w ");
If (! Fp)
{Printf ("cannot"); exit (0 );}
Ch = getchar ();
While (ch! = 'Q ')
{While (ch! = 'Q' & ch! = 'N') <