can anyone tell me where the errors are to get this thing to compile?
Code:
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include <string.h>
#include <ctype.h>
#define MAXSIZE 50
typedef struct {
char elements[MAXSIZE];
int count;
} Stack;
void initialize(Stack *stackPtr);
int isEmpty(Stack *stackPtr);
void push(Stack *stackPtr, int x);
void pop(Stack *stackPtr, int * x);
int main()
{
char PostfixExpression[MAXSIZE + 1];
int LeftOperand, RightOperand;
int Result;
int i;
char c;
char s[MAXSIZE];
int howlong;
Stack EvaluateStack;
initialize(&EvaluateStack);
printf("Enter the postfix expression: ");
fgets(PostfixExpression, sizeof(PostfixExpression), stdin);
howlong = strlen(PostfixExpression);
for(i = 0; i < howlong; i++)
{
c = PostfixExpression[i];
s[0] = c;
s[1] = '\0';
PostfixExpression[i] = c;
if(isdigit(c))
{
push(&EvaluateStack, (int)atof(s));
}
else if(c == '+' || c == '-' || c == '*' || c == '/')
{
pop(&EvaluateStack, &RightOperand);
pop(&EvaluateStack, &LeftOperand);
}
if(c == '+')
{ Result = (LeftOperand + RightOperand);
push(&EvaluateStack, &Result);
}
else if(c == '-')
{
Result = (LeftOperand - RightOperand);
push(&EvaluateStack, &Result);
}
else if(c == '*')
{
Result = (LeftOperand * RightOperand);
push(&EvaluateStack, &Result);
}
else
{
Result = (LeftOperand / RightOperand);
push(&EvaluateStack, &Result);
}
}
}
pop(&EvaluateStack, &Result);
printf("The value of the expression is: %d.\n", Result);
return 0;
}
void initialize(Stack *stackPtr)
{
stackPtr->count = 0;
}
int isEmpty(Stack *stackPtr)
{
if(stackPtr->count == 0)
return 1;
else
return 0;
}
int isFull(Stack *stackPtr)
{
if(stackPtr->count == 50)
return 1;
else
return 0;
}
void push(Stack *stackPtr, int x)
{
if(stackPtr->count == MAXSIZE)
{
printf("The stack is full, aborting...\n");
return;
}
else
{
stackPtr->elements[stackPtr->count] = x;
stackPtr->count++;
}
}
void pop(Stack *stackPtr, int *x)
{
if(stackPtr->count == 0)
{
printf("The stack is empty, cannot delete.\n");
exit(0);
}
else
{
stackPtr->count--;
*x = stackPtr->elements[stackPtr->count];
}
return;
}
Here are the compile errors I get but I can't figure out what is wrong on these lines:
Code:
In function `main':
61: warning: passing arg 2 of `push' makes integer from pointer without a cast
66: warning: passing arg 2 of `push' makes integer from pointer without a cast
71: warning: passing arg 2 of `push' makes integer from pointer without a cast
76: warning: passing arg 2 of `push' makes integer from pointer without a cast
At top level:
83: error: parse error before '&' token
83: error: conflicting types for 'pop'
22: error: previous declaration of 'pop' was here
83: error: conflicting types for 'pop'
22: error: previous declaration of 'pop' was here
83: warning: data definition has no type or storage class
84: error: parse error before string constant
84: error: conflicting types for 'printf'
84: note: a parameter list with an ellipsis can't match an empty parameter name list declaration
84: error: conflicting types for 'printf'
84: note: a parameter list with an ellipsis can't match an empty parameter name list declaration
84: warning: data definition has no type or storage class
125: error: conflicting types for 'pop'
83: error: previous declaration of 'pop' was here
125: error: conflicting types for 'pop'
83: error: previous declaration of 'pop' was here