| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 399 人关注过本帖
标题:编写后缀表达式求值出现问题 求大虾帮忙
只看楼主 加入收藏
simonsun1990
Rank: 1
等 级:新手上路
帖 子:1
专家分:0
注 册:2010-11-2
收藏
 问题点数:0 回复次数:0 
编写后缀表达式求值出现问题 求大虾帮忙
#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 时发生访问冲突

希望大虾们帮忙
搜索更多相关主题的帖子: 后缀 求值 编写 表达 
2010-11-02 10:57
快速回复:编写后缀表达式求值出现问题 求大虾帮忙
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.016659 second(s), 8 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved