使用栈的表达式计算程序_main.c

来源:互联网 发布:opencms mysql 编辑:程序博客网 时间:2024/05/05 06:30
#include<stdio.h>
#include "arith_expr.h"


//char * str = "2+3*4+6";
//char * str = "2+3+6";
//char * str = "2.1+3+6";
//char * str = "2.1+3.0*2";
//char * str = "(2+3.1)*4";
char * str = "2+(3.1-(4-6))";
struct NUM * result;

void output()
{
    printf("output:/n");
    if (result->type == 0)
        printf("%4d/n",result->value.ivalue);
    else
       
        printf("%4.2f/n",result->value.fvalue);
};


int main()
{
     
    init(stdout,str);

    printf("expression is :/n%s/n",str);
    result = compute();

    if (result==NULL)
        printf("The expression is error/n");
    else
        output();
    return(1);
};

 
原创粉丝点击