i am trying to write a program to solve postfix expression but it is giving runtime error.i tried to debug but i am not getting why is it happening can anyone find out.
#include< stdio.h>
#include< string.h>
#include< stdlib.h>
struct stack{
int top;
int n[100];
}s;
int push(char a[]) {
int i,j;
int p=atoi(a);
s.n[s.top+1]=p;
s.top++;
for(i=0;i<100;i++)
a[i]=0;
j=0;
return(j);
}
void pop(char a[])
{
int c,b;
b=s.n[s.top];
c=s.n[s.top-1];
s.top--;
switch(a[0])
{
case '+':
s.n[s.top]=b+c;
break;
case '-':
s.n[s.top]=b-c;
break;
case '*':
s.n[s.top]=b*c;
break;
case '/':
s.n[s.top]=b/c;
break;
}
a[0]=0;
}
int main()
{
s.top=-1;
int m,i,k;
char a[100],c[100];
scanf("%d",&m);
for(i=0;i<m;i++)
{
int j=0;
while(1)
{
scanf("%c",&a[j]);
if(a[j]=='?')
break;
else if(a[j]==' ')
j=push(a);
else if(a[j]=='+'||'-'||'*'||'/')
pop(a[j]);
else
j++;
}
printf("%d",s.n[s.top]);
}
}