📄 main.c
字号:
#include <stdio.h>#include "getop.h" /* getop header file */#include "stack.h" /* stack header file *//* math.h not needed in this version, since atof isn't being used and atoi is not declared there--try "grep atoi /usr/include/math.h" */#define MAXOP 100main(){ int type, op2; char s[MAXOP]; while ((type = getop(s)) != EOF) { switch(type) { case NUMBER: push(atoi(s)); break; case '+': push(pop() + pop()); break; case '*': push(pop() * pop()); break; case '-': op2 = pop(); push(pop() - op2); break; case '/': op2 = pop(); if (op2 != 0) push(pop() / op2); else printf("error : zero divisor\n"); break; /* added for hw4: bitwise or, and, not */ case '|': /* bitwise or */ push(pop() | pop()); break; case '&': /* bitwise and */ push(pop() & pop()); break; case '~': /* bitwise not, i.e., 1's complement */ push(~pop()); break; /* end of new code */ case '\n': printf("The answer is %d.\n", pop()); break; default: printf("error: unknown command %s\n", s); break; } }}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -