title: Evaluating Postfix Expression using stack and array of char with C++
body: <p>I don't know where I do it wrong. Every time I 'pop' in the end of main function it always gave me nothing. I have checked by popping every time before and after I pushing after an operation, and the result is there. But everytime I pop outside the for-loop, the stack gave me nothing. Thanks before, I'm very appreciate your answer.
  P.S = I'm not allowed to use class or OOP. So please don't gave me an answer using those method.</p>
  
  <pre><code>#include&lt;iostream&gt;
  #include&lt;conio.h&gt;
  #include&lt;stdio.h&gt;
  #include&lt;cstdlib&gt;
  #include&lt;cstring&gt;
  
  using namespace std;
  
  typedef struct
  {
      int top;
      int data[20];
  }stack;
  
  void initStack(stack &amp;S)
  {
       int i;
       S.top=-1;
  }
  
  int pop (stack &amp;S)
  {
      int number;
      number = S.data[S.top];
      S.top = S.top - 1;
      return number;
  }
  
  void push(stack &amp;S, int number)
  {
      S.top = S.top + 1;
      S.data[S.top] = number;
  }
  
  void compute(stack &amp;S, char *ch, int n)
  {
      int result;
      for (int i = 0 ; i &lt;= n-1; i++)
      {
          if (ch[i] == '*')
          {
              int operand1 = pop (S);
              int operand2 = pop (S);
              result = operand1 * operand2;
              push(S, result);
          }
  
          else if (ch[i] == '/')
          {
              int operand1 = pop (S);
              int operand2 = pop (S);
              result = operand1 / operand2;
              push(S, result);
          }
  
          else if (ch[i] == '+')
          {
              int operand1 = pop (S);
              int operand2 = pop (S);
              result = operand1 + operand2;
              push(S, result);
          }
  
          else if (ch[i] == '-')
          {
              int operand1 = pop (S);
              int operand2 = pop (S);
              result = operand1 - operand2;
              push(S, result);
          }
  
          else
          {
              result = ch[i] - '0';
              push(S, result);
          }
      }
  }
  
  main()
  {
      stack ST;
      char ch[20];
      initStack(ST);
      cout&lt;&lt;"Please enter the operation: ";
      gets(ch);
      int n = strlen(ch);
      compute(ST, ch, n);
      pop(ST);
  }
  </code></pre>