📄 main.c
字号:
/*main.c;* get a expression from the usr,and a '-' in its tail,* because we think '-' is the lowest valid operator;*AUTHOR:liyangth@gmail.com;*VERSION:1.0;*DATE:2006-8-9;*/#include "handle_opt.h"/*the expresion's size */#define EXP_SIZE 64/*define the oprand_stack*/stack_s oprand_stack;/*define the operator_stack*/stack_s operator_stack; int main(){ char input[EXP_SIZE]; char operator_ch, operator_instack; char oprand_str[8]; int input_len; int oprand_val; int i, j; oprand_stack.sp = 0; /*initlize the stack sp; */ operator_stack.sp = 0; printf("Please input you arithmatic expression:"); scanf("%s", input); input_len = strlen(input); input[input_len] = '-'; input_len++; j = 0; for (i = 0; i < input_len; i++) { if (input[i] >= '0' && input[i] <= '9') { oprand_str[j++] = input[i]; } else { oprand_val = atoi(oprand_str); #ifdef DEBUG //printf("This val get is %d.\n", oprand_val); #endif if ('(' != input[i] && ')' != operator_ch) push(&oprand_stack, oprand_val); #ifdef DEBUG printf("This val put into stack is %d.\n", sp_value(&oprand_stack)); #endif memset(oprand_str, '\0', 8); j = 0; operator_ch = input[i]; switch (operator_ch) { case '(' : handle_left_b(operator_ch); break; case '^' : handle_pow(operator_ch); break; case '/' : case '*' : handle_multi(operator_ch);break; case '+' : case '-' : handle_add_and_sub(operator_ch); break; case ')' : handle_right_b(operator_ch); break; default : break; } } } input[input_len-1] = '\0'; printf("The value of %s is %d.\n", input, pop(&oprand_stack));}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -