Here is my Code:
#include <ctype.h>
#include <string.h>
#include <stdio.h>
#include <stdlib.h>
#define NEW(x) (x * )malloc(sizeof(x))
#define VALID(x) (( * x) != NULL)
#define NUM(x) (( * x) -> num)
typedef ROOT STACK;
int push_double(STACK **stack, double *data)
{
double *ptr;
if((ptr=NEW(double))!=NULL)
{
*ptr = *data;
return(dbl_insert_data(stack,ptr,0));
}
return(-1);
}
int pop_double(STACK**stack, double *data)
{
if(!VALID(stack))
return(-1);
*data = *(double*)((*stack)->head->data);
free((*stack)->head->data);
if(dbl_delete_node(stack,(*stack)->head)==NULL)
return(-1);
else
return 0;
}
int main(void)
{
STACK *stack = NULL;
double d1,d2,d3;
char buff[BUFSIZ];
while(1)
{
gets(buff);
if(buff[0]==NULL)
continue;
if(buff[0]=='c')
{
delete_list(&stack);
printf("Calculator Cleared\n");
continue;
}
if(!isdigit(buff[0])&& strlen(buff)==1)
{
if(!VALID(&stack) || NUM(&stack)<2)
{
printf("Not Enough Arguments\n");
continue;
}
pop_double(&stack,&d1);
pop_double(&stack,&d2);
switch(buff[0])
{
case '+' : d3=d2+d1;
printf("%g+%g=%g\n",d2,d1,d3);
push_double(&stack,&d3);
break;
case '-' : d3=d2-d1;
printf("%g-%g=%g\n",d2,d1,d3);
push_double(&stack,&d3);
break;
case '*' d3=d2*d1;
printf("%g*%g=%g\n",d2,d1,d3);
push_double(&stack,&d3);
break;
case '/' if (d1==0.0);
printf("Divide by zero\n");
else
d3=d2/d1;
printf("%g/%g=%g\n",d2,d1,d3);
push_double(&stack,&d3);
break;
}
}
else
{
d1=atof(buff);
push_double(&stack,&d1);
}
}
return 0;
}
--------------------------------------------------------------------
Here are my compile errors:
Compiling...
RPNC2.cpp
Y:\C Programming\Lab8&9\RPNC2.cpp(19) : error C2146: syntax error : missing ';' before identifier 'STACK'
Y:\C Programming\Lab8&9\RPNC2.cpp(19) : fatal error C1004: unexpected end of file found
Error executing cl.exe.
RPNC2.exe - 2 error(s), 0 warning(s)
--------------------------------------------------------------------
Can anyone please tell me what's wrong with this and how it can be corrected? I know it's straight outta textbook but I thought it strange that it didn't work.
Thanks,
H