user-0 提问: 数据结构——括号匹配，编译没问题，运行时输入以后就没反应了，什么问题？

回复:
user: user-1
content: 帮你修正了， 逻辑再严谨点， 仔细点就好。   #include <stdio.h> #include <stdlib.h> #include <malloc.h>  #define STACK_INIT_SIZE 100 #define STACKINCREAMENT 10  typedef struct {   char *base;   char *top;   int stacksize; }Stack;  int Initstack(Stack &s) {   s.base = (char *)malloc(STACK_INIT_SIZE*sizeof(char));   if(!s.base)  return 0;   s.top = s.base;   s.stacksize = STACK_INIT_SIZE;   return 1;  }   int Pushstack(Stack &s,char c) {   if(s.top - s.base >= s.stacksize)   {     s.base = (char*)realloc(s.base,(STACKINCREAMENT+s.stacksize)*sizeof(char));     if(!s.base) return 0;     s.top = s.base + s.stacksize;     s.stacksize += STACKINCREAMENT;   }   *s.top++ = c;   return 1; }  void Destroystack(Stack &s) {   free(s.base);   s.base = s.top = NULL;   s.stacksize = 0; }  bool Popstack(Stack &s,char &e) {   if(s.top == s.base) return false;   e = * --s.top;   return true; }  bool Isempty(Stack &s) {   return s.base == s.top; }  bool Topstack(Stack& s, char & t) {   if(s.base < s.top)    {     t = s.top[-1];     return true;   }   return false; }  int main() {   char e, top;   bool done = false;   Stack s;   Initstack(s);   int c;   printf("please input something:\n");   while(!done && (c=getchar())!= EOF && c != '\n')   {     switch(c)     {       case '[':       case '(':         Pushstack(s,c);         break;       case ']':         if(Topstack(s, top))          {           if(top == '[')              Popstack(s,e);           else             done = true;         }         break;       case ')':         if(Topstack(s, top))          {           if(top == '(')              Popstack(s,e);           else             done = true;         }         break;     }   }   if(Isempty(s)) printf("Match success!\n");   else printf("Match failed!\n");   Destroystack(s);   //system("pause");   return 0; }

user: user-1
content: 引用 1 楼 user-1 的回复: //if(s.base = s.top ) return 1; if(s.base == s.top ) return 1;   还有好几个这样的例子。

user: user-1
content: //if(s.base = s.top ) return 1; if(s.base == s.top ) return 1;

user: user-0
content: 引用 3 楼 user-1 的回复:帮你修正了， 逻辑再严谨点， 仔细点就好。   #include <stdio.h> #include <stdlib.h> #include <malloc.h>  #define STACK_INIT_SIZE 100 #define STACKINCREAMENT 10  typedef struct {   char *base;   char *top;   int stacksize; }Stack;  int Initstack(Stack &s) {   s.base = (char *)malloc(STACK_INIT_SIZE*sizeof(char));   if(!s.base)  return 0;   s.top = s.base;   s.stacksize = STACK_INIT_SIZE;   return 1;  }   int Pushstack(Stack &s,char c) {   if(s.top - s.base >= s.stacksize)   {     s.base = (char*)realloc(s.base,(STACKINCREAMENT+s.stacksize)*sizeof(char));     if(!s.base) return 0;     s.top = s.base + s.stacksize;     s.stacksize += STACKINCREAMENT;   }   *s.top++ = c;   return 1; }  void Destroystack(Stack &s) {   free(s.base);   s.base = s.top = NULL;   s.stacksize = 0; }  bool Popstack(Stack &s,char &e) {   if(s.top == s.base) return false;   e = * --s.top;   return true; }  bool Isempty(Stack &s) {   return s.base == s.top; }  bool Topstack(Stack& s, char & t) {   if(s.base < s.top)    {     t = s.top[-1];     return true;   }   return false; }  int main() {   char e, top;   bool done = false;   Stack s;   Initstack(s);   int c;   printf("please input something:\n");   while(!done && (c=getchar())!= EOF && c != '\n')   {     switch(c)     {       case '[':       case '(':         Pushstack(s,c);         break;       case ']':         if(Topstack(s, top))          {           if(top == '[')              Popstack(s,e);           else             done = true;         }         break;       case ')':         if(Topstack(s, top))          {           if(top == '(')              Popstack(s,e);           else             done = true;         }         break;     }   }   if(Isempty(s)) printf("Match success!\n");   else printf("Match failed!\n");   Destroystack(s);   //system("pause");   return 0; }   s.top[-1]就是返回栈顶元素么？为什么是这个样子的，那个-1不代表下标，而是代表减1么？