括号匹配,,实在找不出问题了,求助大佬!!

#include
#include

#define MAXSIZE 1001
typedef struct{
char *base;
char *top;
int stacksize;
}SqStack;
char InitStack(SqStack S)
{
S.base=(char *)malloc(MAXSIZE*sizeof(char));
S.stacksize=MAXSIZE;
S.top=S.base;
return 1;
}
char StackEmpty(SqStack S)
{
InitStack(S);
if(S.top-S.base==0)return 0;
else return 1;
}

char GetTop(SqStack S)
{
InitStack(S);
if(S.top-S.base==0)return 0;
return *--S.top;

}
char Push(SqStack *S,char e)
{
InitStack(*S);
*S->top++=e;

}
char Pop(SqStack *S)
{
InitStack(*S);
if(S->top-S->base==0)return 0;
--S->top;

}

int main()
{SqStack S;
InitStack(S);
int flag=1;
char s[MAXSIZE];
gets(s);

int i=0;
int a=0,b=0;
while(s[i]!='#'&&flag)
{

switch(s[i])
{
case '(':
case '[':
a=a+1,Push(&S,s[i]);
break;
case ')':
b=b+1;
if(StackEmpty(S)&&GetTop(S)=='(')Pop(&S);
else flag=0;
break;
case ']':b=b+1;
if(StackEmpty(S)&&GetTop(S)=='[')Pop(&S);
else flag=0;
break;
} i++;
}
printf("%d %d\n",a,b);
if(!StackEmpty(S)&&flag)printf("YES\n");
else printf("NO\n");
return 0;
}

如果问题得到解决,请点下采纳

#include <stdio.h>
#include <stdlib.h>
#define MAXSIZE 1001
typedef struct{
    char *base;
    char *top;
    int stacksize;
}SqStack;
char InitStack(SqStack *S)
{
    S->base=(char *)malloc(MAXSIZE*sizeof(char));
    S->stacksize=MAXSIZE;
    S->top=S->base;
    return 1;
}
int StackEmpty(SqStack S)
{
    //InitStack(S);
    if(S.top-S.base==0)return 0;
    else return 1;
}
char GetTop(SqStack S)
{
    //InitStack(S);
    if(S.top-S.base==0)return 0;
    return *(--S.top);
}
void Push(SqStack *S,char e)
{
    //InitStack(*S);
    *S->top++=e;
}
char Pop(SqStack *S)
{
    //InitStack(*S);
    if(S->top-S->base==0) return 0;
    --S->top; return 1;
}
int main()
{
    SqStack S;
    InitStack(&S);
    int flag=1;
    char s[MAXSIZE];
    gets(s);
    int i=0;
    int a=0,b=0;
    while(s[i]!='#'&&flag)
    {
        switch(s[i])
        {
        case '(':
        case '[':
            a=a+1,Push(&S,s[i]);
            break;
        case ')':
            b=b+1;
            if(StackEmpty(S)&&GetTop(S)=='(')Pop(&S);
            else flag=0;
            break;
        case ']':b=b+1;
            if(StackEmpty(S)&&GetTop(S)=='[')Pop(&S);
            else flag=0;
            break;
        } 
        i++;
    }
    printf("%d %d\n",a,b);
    if(!StackEmpty(S)&&flag)printf("YES\n");
    else printf("NO\n");
    return 0;
}