Error at line 56 and 68. Unable to resolve it.
#include<stdlib.h>
#include<stdio.h>
#include<ctype.h>
#include<string.h>
#include"stack.h"
#include"queue.h"
#include"calcstack.h"
#define MAXSIZE 80
void intopost(stack *stackPtr, queue *queuePtr, char expression[]);
void pushvalue(queue *queuePtr, char item);
void pushop(stack *stackPtr,queue *queuePtr,char item);
void noBracket(stack *stackPtr,queue *queuePtr,char item);
void removeBracket(stack *stackPtr,queue *queuePtr,char item);
int precendence(char op);
float count(queue *queuePtr,calc *calcPtr);
void operation(calc *calcPtr,queue *queuePtr,char op);
int main(void)
{
stack charstack;
queue postfix;
calc numstack;
char expression[MAXSIZE];
float value;
initStack(&charstack);
initQueue(&postfix);
initCalc(&numstack);
printf("Please enter the expression that you want to convert\n");
printf("No spacing in between.\n");
printf("For example: 1+1\n");
scanf("%s", expression);
printf("1\n");
intopost(&charstack, &postfix, expression);
printf("1\n");
append(&postfix, '\0');
printf("Postfix of %s : %s\n", expression, postfix.entry);
printf("1\n");
value=count(&postfix,&numstack);
printf("answer=%.2f\n", value);
}
void intopost(stack *stackPtr, queue *queuePtr, char expression[])
{
for(int i=0; i <strlen(expression) ; i++)
{
if(isdigit (expression[i]) )
{
pushvalue(queuePtr,expression[i]);
}//error
else
{
pushop(stackPtr,queuePtr,expression[i]);
}
}
while(!stackEmpty(stackPtr))
append(queuePtr,pop(stackPtr));
}
void pushvalue(queue *queuePtr, char item)
{
append(queuePtr,item);//error
}
void pushop(stack *stackPtr,queue *queuePtr,char item)
{
if(stackPtr->top == -1)
{
push(stackPtr, item);
}
else
{
if( item != '(' && item != ')' )
{
noBracket(stackPtr,queuePtr,item);
}
else
{
removeBracket(stackPtr,queuePtr,item);
}
}
}
void noBracket(stack *stackPtr,queue *queuePtr,char item)
{
if((precendence(item)) >= (precendence(stackPtr->data[stackPtr->top])))
{
append(queuePtr,pop(stackPtr));
push(stackPtr,item);
}
else
{
push(stackPtr,item);
}
}
void removeBracket(stack *stackPtr,queue *queuePtr,char item)
{
if(item =='(')
{
push(stackPtr,item);
}
else
{
while(stackPtr->data[stackPtr->top]!='(')
{
append(queuePtr, pop(stackPtr));
}
pop(stackPtr);
}
}
int precendence(char op)
{
if( op == '(' || op == ')' )
return 2;
else if(op == '+' || op == '-')
return 1;
else if(op == '*' || op == '/')
return 0;
}
float count(queue *queuePtr,calc *calcPtr)
{
char item;
float value;
for(int i=0;i<strlen(queuePtr->entry);i++)
{
item=serve(queuePtr);
if(isdigit(item))
{
pushNum(calcPtr,float(item - '0'));
}
else
{
operation(calcPtr,queuePtr,item);
}
}
value = popNum(calcPtr);
return value;
}
void operation(calc *calcPtr,queue *queuePtr,char op)
{
float value;
float num1, num2;
switch(op)
{
case '*': { num2=popNum(calcPtr);
num1=popNum(calcPtr);
value=num1 * num2;
pushNum(calcPtr,value);
break;
}
case '/': { num2=popNum(calcPtr);
num1=popNum(calcPtr);
value=num1/num2;
pushNum( calcPtr, value );
break;
}
case '+': { num2=popNum(calcPtr);
num1=popNum(calcPtr);
value=num1+num2;
pushNum(calcPtr,value);
break;
}
case '-': { num2=popNum(calcPtr);
num1=popNum(calcPtr);
value=num1-num2;
pushNum(calcPtr,value);
break;
}
default : { serve(queuePtr);
break;
}
}
}