title: postfix calculator does not work, why? - C
body: <p>i have postfix calculator, but he is not working, can you please help me? 
  I want calculate postfix expression <code>2 sin 2 cos / 5 *</code>
  Output is <code>5.000000</code>, but correct output is <code>0.17...</code>
  Calculations work!
  I think the problem is somewhere in adding expressions to the stack.
  Thank you for any advice!</p>
  
  <pre><code>    const char *arrayPostfix[1000];
  
          //.
          //.
          //.
          //Filling the field
          //field contents:
          //2 &lt;SIN&gt; 2 &lt;COS&gt; &lt;/&gt; 5 &lt;*&gt;
  
          const char *stack[1000];
          int counter = 0;
          int i;
          int numberofElement = 7; // the number of elements - 2 &lt;SIN&gt; 2 &lt;COS&gt; &lt;/&gt; 5 &lt;*&gt;
          char myString[100];
          double help;
  
          for (i = 0; i &lt; numberofElement; i++) {         
  
  
              if (arrayPostfix[i][0] != '&lt;') {
                  // IS A NUMBER
                  stack[counter] = arrayPostfix[i];
                  counter++;
  
              } else {
                  // IT ISNT NUMBER
                  //// GET LAST OPERATOR - typedef struct 
                  // this works
                  operator lastOperator;
                  int x = 0;
  
                  for (x = 0; x &lt; sizeof(operatory) / sizeof(operator); x++) {
                      if (strcmp(arrayPostfix[i], operatory[x].nazev) == 0) {
                          lastOperator = operatory[x];
                          break;
                      }
                  }
                  // Operators are ok..
  
                  double n1, n2;
  
                  if (lastOperator.numberofOperators == 2) {// a+b, a-b, a*b, a/b
  
                      counter--;
                      n1 = atof(stack[counter]);//string to double
  
  
                      counter--;
                      n2 = atof(stack[counter]);//string to double
  
  
                      help = lastOperator.funkce_dvaOperator(n2, n1); // this works, calculate
                      sprintf(myString, "%f", help); //double to string
  
                      stack[counter] = myString;
                      counter++;
  
                  } else { // sin(a), cos(a)....
  
                      counter--;
                      n1 = atof(stack[counter]); //string to double
  
                      help = lastOperator.funkce_jedenOperator(n1);   // this works, calculate        
  
                      sprintf(myString, "%f", help); //double to string
  
                      stack[counter] = myString;
                      counter++;
  
                  }
  
              }
                      return atof(stack[0]);
          }
  </code></pre>
  
  <p>steps:</p>
  
  <pre><code>1) add number 2
  --------------------------------------------
  Index [ 0 ] je : 2
  --------------------------------------------
  
  
  2) calculate sin(2)
  --------------------------------------------
  Index [ 0 ] je : 0.034899
  --------------------------------------------
  
  
  3) add number 2 - but in stac [0] is fail value..why?
  --------------------------------------------
  Index [ 0 ] je : 0.034899
  Index [ 1 ] je : 0.034899
  </code></pre>