main.c

来自「Multi-module programs and MAKE」· C语言 代码 · 共 58 行

C
58
字号
#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 + =
减小字号Ctrl + -
显示快捷键?