C/C++ 简单括号匹配问题

我的程序,运行检测的括号匹配和实际不符麻烦帮忙看下问题

 #include<stdio.h>
typedef struct
{
    char ch[50];
    int top;
}SeqStack;
int Push(SeqStack &S,char x)
{
    if(S.top==49) return 0;
    S.top++;
    S.ch[S.top]=x;
    return 1;

}
int Pop(SeqStack &S,char x)
{
    if(S.top==-1) return 0;
    x=S.ch[S.top];
    S.top--;
    return 1;

}
int GetTop(SeqStack &S,char x)
{
    if(S.top==-1) return 0;
    x=S.ch[S.top];
    return 1;

}
int BracketMatch(char str[])
{
    SeqStack S;
    int i;
    char ch;
    S.top=-1;
    for(i=0;str[i]!='#';i++)
    {
        switch(str[i]){
        case'(':
        case'[':
        case'{':
            Push(S,str[i]);
            break;
        case')':
        case']':
        case'}':
            if(S.top==-1) {printf("\nÓÒÀ¨ºÅ¶àÓà");return 0;}
             else 
             {
                 GetTop(S,ch);
                 if((str[i]==')'&&ch=='(')||(str[i]==']'&&ch=='[')||(str[i]=='}'&&ch=='{')) Pop(S,ch);
                 else  {printf("\n¶ÔÓ¦µÄ×óÓÒÀ¨ºÅ²»Í¬Àà");return 0;}
             }
            }

    }if(S.top==-1)   {printf("\nÀ¨ºÅÆ¥Åä");return 1;}
        else printf("\n×óÀ¨ºÅ¶àÓ࣡");
    return 0;
}
void main()
{
    char ch[50];
    int i=0;
    char c;
    c=getchar();
    while(c!='\n')
    {
        ch[i]=c;
        c=getchar();
        i++;
    }
    BracketMatch(ch);
}

{ if(S.top==-1) {printf("\nÓÒÀ¨ºÅ¶àÓà");return 0;}
else
{
GetTop(S,ch);
if((str[i]=='('&&ch==')')||(str[i]=='['&&ch==']')||(str[i]=='{'&&ch=='}')) Pop(S,ch);
else {printf("\n¶ÔÓ¦µÄ×óÓÒÀ¨ºÅ²»Í¬Àà");return 0;}
}
}

去掉最外层的括号试试