title: Wrote a C++ code to check if expression has balanced parenthesis and my code is not running. I have been stuck for a day now
body: <p>The code is given below. There is no syntax error and the code used to run perfectly fine if i checked match for only () parenthesis but after i added some if.. else.. statements to check match for other brackets, my code broke. I am unable to figure out my mistake. Please Help!! I think i did some silly mistake but can't figure out what.</p>
  
  <pre><code>// structure of a stack
  
  struct stackStructure
  {
      // top pointer of the stack
      int top;
      // pointer to the array/stack
      char *array;
  }stack;
  
  // function to push element to stack
  
  void push(char data)
  {
      if(stack.top == 999)
      {
          cout&lt;&lt;"Stack Overflow"&lt;&lt;endl;
          return;
      }
      else
      {
          // incrementing the top and then pushing data to the stack
          stack.top++;
          stack.array[stack.top]= data;
      }
  } // end of push() function
  
  // function to pop elements from the stack
  
  char pop()
  {
      if(stack.top == -1)
          return '\0';
      else
          // returning the popped value and then decrementing the top pointer
          return stack.array[stack.top--];
  } // end of pop() function
  int main()
  {
      // match variable to keep track that closing bracket and opening brackets are in sequence
      char match= '\0';
      bool isMatching= true;
      // resetting the stack variables and attributes
      stack.top= -1;
      stack.array= new char[1000];
      cout&lt;&lt;"Enter the Expression to match the parenthesis: ";
      cin&gt;&gt;stack.array;
  
      // traversing through the character array and matching parenthesis
      for(int i=0; stack.array[i] != NULL; i++)
      {
          // if character is an opening bracket
          if(stack.array[i] == '(' || stack.array[i] == '{' || stack.array[i] == '[')
              push(stack.array[i]);
          // if character is a closing bracket
          else if(stack.array[i] == ')' || stack.array[i] == '}' || stack.array[i] == ']')
          {
              match= pop();
              if(stack.array[i] != match)
                  isMatching= false;
          }
          // if character is anything else we do nothing
          else
              continue;
      }
      if(isMatching == true)
          cout&lt;&lt;"Parenthesis Matched"&lt;&lt;endl;
      else
          cout&lt;&lt;"Not matched"&lt;&lt;endl;
      return 0;
  }
  </code></pre>