postfix evaluation

Hi, i'am trying to read postfix expression from txt file and evaluate it
the input is 10 5 * ,the output should be 50, but it reads only 10 and 5, where's the error?
here's my code
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
#include <iostream>
 #include <iomanip>
 #include <fstream>
 #include<stdio.h>
 #include<ctype.h>
 #include<stdlib.h>
 using namespace std;
 #define SIZE 40
 int stack[SIZE];
 int top=-1;
 
void push(int n)
 {
 if(top==SIZE-1)
 {
 printf("Stack is full\n");
  system("pause");
 return;
 }
 else
 {
 top=top+1;
 stack[top]=n;
 printf("Pushed element is %d\n",n);
  system("pause");
 }
 }
 
int pop()
 {
 int n;
 if(top==-1)
 {
 printf("Stack is empty\n");
  system("pause");
 return 0;
 }
 else
 {
 n=stack[top];
 top=top-1;

 return(n);
 }
 }
 



int main() 
{
 
int str[50],ch;

 int i=0;
 int n,op1,op2;

 ifstream inFile;
 ch=str[i];

 inFile.open("D:\\me.txt");
 if (!inFile) 
{
 printf( "Unable to open file");
 system("pause");
 exit(1); // terminate with error
 }

 while (inFile >> ch) 
{
 if(ch==43 || ch==45 || ch==47 || ch==42 || ch==94 || ch==37 )
 {

	 op1=pop();
	 op2=pop();
	 if (op1<op2)
	 {
	 n=op1;
	 op1=op2;
	 op2=n;
	 }
	 switch(ch)
	 {
	 case 43:
	 n=op1+op2; break;
	 case 45:
	 n=op1-op2;break;
	 case 42:
	 n=op1*op2;break;
	 case 47:
	 n=op1/op2;break;
	 case 37:
	 n=op1%op2;break;
	 case 94:
	 n=op1^op2;break;
	
 
	 default:
	 {
	 printf("The operator is not identified\n");
	 system("pause");
	 exit(0);break;
	 }
	 }
	 printf("n=%d\n",n);
	 push(n);
	 system("pause");


 }
	 else
	 {
	 n=ch;
	 push(n);
	 }
 ch=str[++i];
 }
inFile.close();
 printf("The value of the arithmetic expression is=%d\n",pop());
 system("pause");
 return 0;
 }

The variable str is not doing you anything as far as I can tell.

Are you sure that when you extract from a stream in to an integer that it will accept any ANSI character? (i.e., reading a [non-alphanumeric] character in to an integer probably fails the stream)

Case 94 probably does not do what you expect.

What kind of output are you getting?

he only pushes 10 & 5 into stack, and gives final evaluation as 5 !!
the problem he can't read operators neither their ascii ??
Topic archived. No new replies allowed.