编写后缀表达式求值出现问题 求大虾帮忙
#include <stdio.h>#include <string.h>
#define MAX_STACK_SIZE 100
#define MAX_EXPR_SIZE 100
typedef enum {lparen,rparen,plus,minus,times,divide,mod,eos,operand} precedence;
int stack[MAX_STACK_SIZE];
char expr[MAX_EXPR_SIZE];
void add(int *top0,int *item)
{ stack[++(*top0)]=item;}
int delete(int *top1)
{return stack[(*top1)--];}
int eval(void)
{
precedence token;
char symbol;
int op1,op2;
int n=0;
int top=-1;
token= get_token(&symbol,&n);
while(token!=eos)
{if (token==operand)
add(&top,symbol-'0');
else{
op2=delete(&top);
op1=delete(&top);
switch(token){
case plus:{add(&top,op1+op2);break;}
case minus:{add(&top,op1-op2);break;}
case times:{add(&top,op1*op2);break;}
case divide:{add(&top,op1/op2);break;}
case mod:add(&top,op1%op2);}
}
token=get_token(&symbol,&n);
}
return delete(&top);
}
precedence get_token(char *symbol1,int *n1)
{
symbol1=expr[(*n1)++];
switch (*symbol1)
{
case'(' : return lparen;
case')' : return rparen;
case'+' : return plus;
case'-' : return minus;
case'*' : return times;
case'/' : return divide;
case'%' : return mod;
case' ' : return eos;
default: return operand;
}
}
int main()
{int i=0,result;
do
{scanf("%c",expr[i++]);}
while(expr[i-1]!=' ');
result= eval;
printf("%d",result);
return 0;
}
程序debug通过,但是运行时出现如下错误
assignment3.exe 中的 0x102a3aa0 (msvcr80d.dll) 处未处理的异常: 0xC0000005: 写入位置 0x00000000 时发生访问冲突
希望大虾们帮忙