/*** * @author banxi1988 * @mail banxi1988 at gmail.com * @qq 787928000 * 一个简单的四则运算器。C语言实现。暂时无法实现处理括号。 * @bug-report : if have any suggestion and find any bug please send mail to my mail or send massage to my qq! thanks */ #include<stdio.h> #include<stdlib.h> #include<string.h> #include<time.h> //#define BANXI_DEBUG 1 #define MAX_LEN 1024 #define D_BIT_LEN 32 /*** * 一些有用的宏,关于字符操作 */ #define is_operator(ch) (strchr("+-*/",(ch)) != NULL) // 判断是否是运算符 #define is_muldiv(ch) (strchr("*/",(ch)) != NULL) // 判断是否是乘法或除法 #define is_end_input(ch) (ch == EOF || ch == '/n') //判断是否是输入的结尾。一次只允许输入一行。所以.. typedef enum OP_TYPE_TAG{OPERAND,OPERATOR}OP_TYPE; typedef enum READ_STATE{R_OPERAND,R_OPERATOR}READ_TYPE; typedef struct OP_ITEM_TAG{ double operand; char operator; OP_TYPE op_type; }OP_ITEM; OP_ITEM op_items[MAX_LEN] = {{0,0,0}}; int items_count = 0; READ_TYPE read_type = R_OPERAND; int remove_space(){ char ch; while(isspace(ch=getchar())); ungetc(ch,stdin); }//end remove_space int bits_length_tips(int index){ if(index > 37){ printf("WARNING:YOU HAVE INPUT A TOO LARGER NUMBER,IF HAVE NO POINT!/n"); }else if(index > D_BIT_LEN){ printf("WARNING:YOU HAVA INPUT A LARGER NUMBER!/n"); }// }//end bits_length_tips int input_data(){ char buffer[D_BIT_LEN] = {'/0'}; char operator = 'a'; double operand = 0.0; char ch = 'a'; int index = 0; //for digit bit count int flag = 0; //for float . token count read_type = R_OPERAND; // 先读操作数 while(1){ if(read_type == R_OPERAND){ remove_spac