K & R C Programs Exercise 5-10.

K and R C, Solution to Exercise 5-10:
K and R C Programs Exercises provides the solution to all the exercises in the C Programming Language (2nd Edition). You can learn and solve K&R C Programs Exercise.
C Program to evaluate reverse Polish expression from the command line, where each operator or operand is a separate argument.
For example:expr 2 3 4 + * evaluates 2 X (3 + 4). Read more about C Programming Language .
/***********************************************************
* You can use all the programs on www.c-program-example.com
* for personal and learning purposes. For permissions to use the
* programs for commercial purposes,
* contact info@c-program-example.com
* To find more C programs, do visit www.c-program-example.com
* and browse!
*
* Happy Coding
***********************************************************/


#include <ctype.h>
#include <stdio.h>
#include <stdlib.h>

#define MAX 1000

double stack[MAX];
int stack_height = 0;

void panic(const char *msg) {
fprintf(stderr, "%sn", msg);
exit(EXIT_FAILURE);
}

void push(double value) {
if (stack_height == MAX)
panic("stack is too high!");
stack[stack_height] = value;
++stack_height;
}

double pop(void) {
if (stack_height == 0)
panic("stack is empty!");
return stack[--stack_height];
}

int main(int argc, char **argv) {
int i;
double value;

for (i = 1; i < argc; ++i) {
switch (argv[i][0]) {
case '