To save you time, we have provided the skeleton of the program in
the file named stacklab.c, embedded in a project. First, download the
project archive stacklab.zip into your home
directory. Then, from Elcipse, import this project into your workspace
in the usual way: under "File", select "Import...", then under
"General" select "Existing projects into workspace', click "Next", then
click the button "Select archive file" and browse for the file
"stacklab.zip" in your home directory. Now open the imported project,
"stacklab", inside which you will notice, among other things, the
following files:
"stacklab.c", the source file that you have to edit;
"lab14", an executable that you can run to see how you program is
supposed to work.
To run "lab14" from the Unix prompt, type lab14, then enter your RPN
expression and hit <Enter> on the keyboard and then CNTRL-d on
the keyboard.
For example
> lab14
3 4 5 + -
and then press the Enter key and then press the d
key down while
holding down the Control Key. You should get -6 as an answer.
Here is the flow chart for the stacklab recursive function.


Locate the code for the recursive function named "stacklab" located
in your Eclipse editor in the the stacklab.c file. You will have
to complete the code for this function.
1. Complete the code for the logical condition. Find the
comment that needs to be removed that states:
if ( /*remove this comment and replace with
a logical condition */ )
Replace the comment with the correct code that corresponds
to the flowchart above. You must use the "isnumber" function we provide
for you. The code for this function is found in
your file but we repeat it here too (important! note the
datatype of ptr, so when you call isnumber what do you pass in the
second argument?):
/* return 1 if string can be converted to a number else return 0 */
/* ptr points to a variable in the calling function. if string holds a
number then */
/* (*ptr) is assigned that number */
int isnumber(char string[], double * ptr)
{
double result;
char * end = string;
char * previous_end;
previous_end = end;
result = strtod(string, &end);
if (previous_end == end)
return 0; /* not a number */
else
{
*ptr = result; /* assign number to variable in
calling function */
return 1; /* is
a number */
}
}
2. Complete the cases for the other operators and functions.
Hints: Use pow for ^, for functions like
sin, cos, tan, sqrt, you will need to decrease the stack top by one and
not by two.
Answer questions 5 - 11 on the answer sheet.
Obtain a TA signature on the answer sheet.
That's all folks! Hand in your answer sheet to your TA.