#include<stdio.h>
#define TRue 1
#define ERror 0
#define maxsize 100

typedef struct
{ char a[100];
  int top;
}stack;

/*stack *s;*/
initstack(stack *s)
{s->top=0;}

int emptystack(stack s)
 {if(s.top==0) return 1;
  else return 0;}

char get_top(stack s)
 {if(s.top==0) return 0;
  else
      return s.a[s.top-1];
}

push(stack *s,char ch)
 {
  if((s->top)==maxsize )
     {printf("栈已满,不能插入"); return 0;}
  s->a[s->top]=ch;
  s->top++;
}

pop(stack *s)
 {
  if(s->top==0) {printf("栈是空的,不能删除");return 0;}
  s->top--;
 }

int match_kuohao(char c[])
 {   int i=0;
   stack s;

   initstack(&s);
   while(c[i]!='#')
   {
     /* if(c[i]!='['||c[i]!=']'||c[i]!='('||c[i]!=')'||c[i]!='{'||c[i]!='}')
       return 0; */
     switch(c[i])
     {
       case '{':
       case '[':  
       case '(':push(&s,c[i]);break;
       case '}':if(!emptystack(s)&&get_top(s)=='{')
               {pop(&s);break;}
                 else return 0;
       case ']':if(!emptystack(s)&&get_top(s)=='[')
              {pop(&s);break;}          else return 0;
       case ')':if(!emptystack(s)&&get_top(s)=='(')
              {pop(&s);break;}          else return 0;
     }
     i++;
   }
   return (emptystack(s));/*栈空则匹配,否则不匹配*/
 }                            

main()
{char  c[maxsize];
 int j;
 printf("please input the string:\n");
 gets(c);
 j=match_kuohao(c);
 if(j) printf("they are match\n");
 else printf("not match\n");
 getch();
}在WIN-TC下调试通过
 
我在论坛中也看到了些相关的括弧匹配的程序,作者说调试通过了,
可为什么我复制在WIN-TC环境中编译不能通过呢,请指点谢谢。还有就是我觉得有些朋友的程序
好象有点缺陷,就是没有考虑没括弧的情况。不知道我的理解是不是对的,请指点。