/*设计一个简单的文字编辑器,使其具有删除打错字符的功能*/
/*约定:@表示删除前面一个字符,#表示删除前面所有字符,$表示编辑结束*/
#include
#define maxsize 64
typedef struct
{
void* data[maxsize];
int top;
}seqstack;
void SETNULL(seqstack *s){
s->top=-1;printf("cei1\n");printf("%d",s->top);
}
int EMPTY(seqstack *s){
printf("cei10\n");
if(s->top>=0)
return 0;
else
return 1;
}
char POP(seqstack *s)
{ printf("cei2\n");
if(EMPTY(s))
{
printf("underflow");
return NULL;}
else
{
s->top--;
return(s->data[s->top+1]);
}
}
seqstack *PUSH(seqstack *s,char x){
printf("cei3\n");
int i;
if(s->top==maxsize-1)
{
printf("overflow");
return NULL;
}
else
{
s->top++;
s->data[s->top]=x;
}
return s;
}
void shuchu(seqstack *s){
printf("cei4\n");
int i=-1;
printf("字符为\n");
while(i!=s->top){
printf("%s\t",s->data[i+1]);
i++;
}
}
void EDIT(seqstack *s)
{
char c;
SETNULL(&s); printf("cei5\n");
c=getchar();
while(c!='$')
{
if(c=='@') {
POP(&s); printf("cei6\n");
}
else if(c=='#') {
SETNULL(&s); printf("cei7\n");
}
else {printf("1%d",s->top);
PUSH(&s,c); printf("cei8\n");
}
getchar();
shuchu(&s); printf("cei9\n");
c=getchar();
}
}
void main()
{
seqstack *s;
EDIT(s);
}