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;
				} 

	}
}

Recommended Answers

All 4 Replies

What was the error messages?

Debug Assertion failed

file:f:\dd\vctools\crt_bld\self_x86\crt\src\isctype.c
Line:56
Expression:(unsigned)(c+1)<=256

I think you might have a problem with the two stack.h files you've included. calcstack.h and stack.h are likely to have some of the same definitions and leave the compiler tied up in knots.

Check for keyboard errors in your code, if they're supposed to be compatible.

Were you supposed to add an #ifndef block of code ?

Consider switching to unsigned char s altogether, or at the minimum, cast to unsigned char whatever you pass to isdigit() .

PS. When you post code/error messages, please tick the "Disable smilies in text" option before you post (see your second post ^^).

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.