blob: b65b44d541cb6996a6db04566ee5c595df7360dd (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
|
#include <stdio.h>
#include <stdlib.h>
#include "stk.h"
#include "op.h"
#define MAXOP 100
int main(void)
{
char op[MAXOP];
int opd2;
int c;
while ((c = getop(op, MAXOP)) != EOF) {
switch (c) {
case NUM:
push(atof(op));
break;
case '+':
push(pop() + pop());
break;
case '-':
opd2 = pop();
push(pop() + opd2);
break;
case '*':
push(pop() * pop());
break;
case '/':
opd2 = pop();
push(pop() / opd2);
break;
case '\n':
printf("\tans: %.2lf\n", pop());
clear();
break;
default:
printf("err: unkown operator: %c\n", c);
break;
}
}
return 0;
}
|