Problem: Write a program, named p3.c , that behaves in the manner describe in the "usage" message listed below, either printing the usage message when the first command-line argument is -- help ", or accepting input from stdin . You should write appropriate error messages to std out if an error arises, whether an unrecognized command-line argument, a stack underflow or overflow, or unrecognized input.
Naming: Your submitted file is to be named p3.c
Output: Your program's output must be to stdout and of one of the four formats following, assuming argc and argv are the usual parameters for main() and where < program_name> is argv[0] , and rnum is any real number in decimal format.
If argv[1] is " -- help ", display the following.
Usage: < program_name>
"< program_name> --help"
display thi i s usage material.
"< program_name> -rpn"
The program accepts input from standard input as a sequence
of numbers and operators. The numbers (operands, as
integers or floating point numbers) read are push ed on a
stack until needed. When an operator is read, the required
operands are popped from the stack and used to perform the
calcu lation, with the result placed on the stack. Valid
operators are +, -, * and /, are interpreted as addition,
subtraction, multiplication and division, respectively, as
described below. An additional operator is =, which
indicates that the value a t the top of the stack is popped
from the stack and displayed along with the number of
values remaining on the stack, whereupon the program
terminates.
Stack underflows generate an error message and halt the
program, as do a stack overflowss. Unrecognized input
tokens produce error messages and result in program
termination, as do unrecognized command line arguments.
The size of the stack is 10.
Stack operations are performed as indicated here.
+ : push(pop() + pop());
- : temp = pop(); push(pop() – temp;
* : push(pop() * pop());
/ : temp = pop(); push(pop() / temp;
= : pop the stack top and display it as the result
with the number of items remaining on the stack.
The above describes the majority of the behavior of the program you are to write. To reiterate and expand important points:
Result = < result popped from top of stack>.
< number of operands on the stack> values remain on the stack.
For all error conditions, print the required output to stderr.
Remember that any item delimited by angle brackets ("< >") is to be replaced with the appropriate information, without the angle brackets.