递归实现表达式运算(C语言)

通过递归的方法实现简单表达式的运算,支持加减乘除以及多层括号运算。

//eval.h

//
//eval.h

#if !defined(__EVAL__H__)
#define __EVAL__H__

//  evaluate the value of the str.
//  It support +-*/ with non-nagetive integers only.
//  @param str The string to be evaluated. This string is to be modified.
//  @return the value evaluated.
int eval(char* str);

#endif 

//eval.c

//
//eval.c 

#include "eval.h"
#include <string.h>
#include <stdio.h>

#define CH2DEC(x) ((x) - '0')

//  find the most right and lowest operator in the str
//  @return -1 if no any operators in the str; or
//  the index of the operator sepeicified in the str
static int findop(const char *str);

//  return the rank of the operator
//  @return -1 if the char ch is not an operator; or
//  the rank listed as 1 for * and /, 2 for + and -
static int oprank(char ch);

//  convert a string into a number.
//  The string s
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值