- #1
Peon666
- 108
- 0
Alright guys, I was implementing RPN calculator in C language and during that, I have a little problem with the summing and poping thing. Here's how it goes:
My code is here:
Now the problem is that this does not add the two integers. Why is this happening? Besides, it does not take anything in array2[0] and array2[1]. When I pop the elements array[0] and array[1] into array2[0] and array2[1] and print them out, only 1 is printed out. What could be the problem?
Further, when I add array[0] and array[1] into temp and print temp out, again, 1 is printed and nothing else. However, if I print out array[0] and array[1] separately, they are displayed as I enter them, i.e 3 and 4. What's going on? I'm really troubled about this fiasco! :(
My code is here:
case '+':
if (i < 2)
printf ("Not enough operators to perform addition operation!\n");
array2[0] = pop(mystack, &array[0]); // Output: 1
array2[1] = pop(mystack, &array[1]); // Output: 1
printf ("%d\n", array[0]); // Output: 3 (as I entered)
printf ("%d\n", array[1]); // Output: 4 (as I entered)
temp = (array[0]+array[1]);
push (mystack, temp);
printf ("%d\n", temp); // Output: 1
temp2 = pop (mystack, &temp);
printf ("%d\n",temp2); // Output: 1
break;
Now the problem is that this does not add the two integers. Why is this happening? Besides, it does not take anything in array2[0] and array2[1]. When I pop the elements array[0] and array[1] into array2[0] and array2[1] and print them out, only 1 is printed out. What could be the problem?
Further, when I add array[0] and array[1] into temp and print temp out, again, 1 is printed and nothing else. However, if I print out array[0] and array[1] separately, they are displayed as I enter them, i.e 3 and 4. What's going on? I'm really troubled about this fiasco! :(