hi...following code is for postfix evaluation.....after executing the code i am getting segmentation fault error....can u help me to solve this error and what is segmentation error?
#include<iostream>
#include<string.h>
using namespace std;
class post_evaluation
{
public:
int val;
post_evaluation *nxt;
void push(int i);
void add();
void sub();
};
post_evaluation *top=NULL;
void post_evaluation::push(int i)
{
post_evaluation *t;
t->val=i;
t->nxt=NULL;
top=t;
}
void post_evaluation:: add()
{
post_evaluation *t;
t->val=top->val;
top=top->nxt;
t->val=t->val+top->val;
t->nxt=top->nxt;
top=t;
}
void post_evaluation::sub()
{
post_evaluation *t;
t->val=top->val;
top=top->nxt;
t->val=t->val-top->val;
t->nxt=top->nxt;
top=t;
}
int main()
{
post_evaluation o;
char exp[100];
int i=0;
cout<<"Enter your expression....:\n";
cin>>exp;
// for(i=0;exp[i]!='\0';i++)
while(exp[i]!='\0')
{
//cout<<";
switch(exp[i])
{
case '+':
o.add();
break;
case '-':
break;
case '*':
break;
case '/':
break;
default :
if(exp[i]!='\0')
{
int x=int(exp[i]);
o.push(x);
}
else
cout<<"No expression......";
break;
}
}
cout<<char(top->val);
i++;
}