home *** CD-ROM | disk | FTP | other *** search
- #include <stdio.h>
-
- #define MAXOP 20
- #define NUMBER '0'
- #define TOOBIG '9'
-
- main()
- {
- int type;
- char s[MAXOP];
- double op2, atof(char *), pop(void), push(double);
- void clear(void);
- int getop(char *s, int lim);
-
- while ((type = getop(s, MAXOP)) != EOF)
- switch (type)
- { case NUMBER: push(atof(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.0)
- push(pop() / op2);
- else
- printf("zero divisor popped\n");
- break;
- case '=': printf("\t%f\n",push(pop()));
- break;
- case 'c': clear();
- break;
- case TOOBIG: printf("%.20s ... is too long\n",s);
- break;
- default: printf("unknown command %c\n", type);
- break;
- }
- }