1 Replies - 425 Views - Last Post: 10 August 2008 - 03:32 AM Rate Topic: -----

#1 qaz1134  Icon User is offline

  • D.I.C Head

Reputation: 2
  • View blog
  • Posts: 121
  • Joined: 21-May 08

what is this kind of error?

Posted 10 August 2008 - 02:53 AM

hello guys i really need your help on this please help me!!!

here is my code

176 - 179 error structure required on left side of - or-* ?????? what is it???
#include <stdio.h>
#include <conio.h>
#include <malloc.h>
#include <string.h>

// the nodes of the stack
typedef struct my_struct{
	char value;
	struct my_struct *pNext;
}item, *itemptr;

//popped data
char popData;

//push item into stack
itemptr push(char c, itemptr pBottom, int numNodes){
	itemptr pNewNode, pCurrent;
	int traversalCount=0;
	pNewNode = (itemptr)malloc(sizeof(item));
	pNewNode -> value = c;
	pNewNode -> pNext = NULL;
	if (pBottom==NULL){
		pBottom = pNewNode;
	} else {
			pCurrent = pBottom;
			while (pCurrent!=NULL){
				traversalCount++;
				if (traversalCount+1==numNodes){
					break;
				}
				pCurrent=pCurrent->pNext;
			}
			pNewNode->pNext = pCurrent->pNext;
			pCurrent->pNext = pNewNode;
	}
	return pBottom;
}

//pops an item on to the stack
itemptr pop(itemptr pBottom, int numNodes){
	itemptr pCurrent, pFollower;
	int traversalCount=1;
	if (pBottom == NULL){
		popData = '\0';
	} else {
		if (numNodes!=1){
			pCurrent = pBottom;
			pFollower = pBottom;
			do{
				traversalCount++;
				pFollower = pCurrent;
				pCurrent=pCurrent->pNext;
			} while (traversalCount!=numNodes);
			pFollower -> pNext = pCurrent->pNext;
			popData = pCurrent->value;
			free(pCurrent);
		} else {
			pCurrent = pBottom;
			popData = pCurrent -> value;
			free(pCurrent);
		}
	}
	return pBottom;
}

//display stacks value
void display(itemptr pBottom){
	itemptr pCurrent;
	if (pBottom==NULL){
		printf(" none");
	} else {
		pCurrent = pBottom;
		while(pCurrent!=NULL){
			printf("%c", pCurrent->value);
			pCurrent=pCurrent->pNext;
		}
	}
}

int icp(char x){
	int y;
	if ((x=='+')||(x=='-')){
		y=1;
	} else if ((x=='*')||(x=='/')){
		y=2;
	} else if (x=='^'){
		y=4;
	} else if (x=='('){
		y=5;
	} else if (x==')'){
		y=6;
	} else {
		y=-1;
	}
	return y;
}

int isp(char x){
	int y;
	if ((x=='+')||(x=='-')){
		y=1;
	} else if ((x=='*')||(x=='/')){
		y=2;
	} else if (x=='^'){
		y=3;
	} else if (x=='('){
		y=0;
	} else {
		y=-1;
	}
	return y;
}
char getItem(int position, itemptr pBottom){
	itemptr pCurrent;
	pCurrent = pBottom;
	int traversalCount=0;
	do{
		if (traversalCount==position-1){
			break;
		}
		pCurrent=pCurrent->pNext;
		traversalCount++;
	} while (1);
	return pCurrent->value;
}
void infixtopostfix(itemptr s){
	itemptr stack, output, invalid;
	int i=1, stackNumNodes=0, outputNumNodes=0, invalidNumNodes=0;
	char pp, c;
	stack=NULL;
	output=NULL;
	invalid=NULL;
	stackNumNodes++;
	stack=push('\0', stack,stackNumNodes);
	stackNumNodes++;
	stack=push('(', stack,stackNumNodes);
	c = getItem(i, s);
	while(c!='\0'){
		if (((c>='A')&&(c<='Z'))||((c>='a')&&(c<='z'))||((c>='0')&&(c<='9'))){
			outputNumNodes++;
			output=push(c, output, outputNumNodes);
		} else {
			if (c==')'){
				while (getItem(stackNumNodes, stack)!='('){
					stack=pop(stack, stackNumNodes);
					stackNumNodes--;
					outputNumNodes++;
					output=push(popData, output, outputNumNodes);
				}
				stack=pop(stack, stackNumNodes);
				stackNumNodes--;
			} else if ((c=='+')||(c=='-')||(c=='*')||(c=='/')||(c=='(')||(c=='^')){
				while (icp(c)<=isp(getItem(stackNumNodes, stack))){
					stack = pop(stack, stackNumNodes);
					stackNumNodes--;
					outputNumNodes++;
					output = push(popData, stack, outputNumNodes);
				}
				stackNumNodes++;
				stack = push(c, stack, stackNumNodes);
			} else{
				invalidNumNodes++;
				invalid = push(c, invalid, invalidNumNodes);
			}
		}
		i++;
		c=getItem(i, s);
	}
	printf("The postfix expression is: ");
	display(output);
	if (invalidNumNodes!=0){
		printf("\nThe expression contains the following invalid inputs: ");
		display(invalid);
	}
	do{
		s.pop();
		output.pop();
		stack.pop();
		invalid.pop();
	}while((!(output==NULL))&&(!(stack==NULL))&&(!(s==NULL))&&(!(invalid==NULL)));
}
void main(){
	itemptr input;
	input=NULL;
	clrscr();
	int numNodes=0;
	int x, y;
	char expression[100];
	printf("Enter an infix expression: ");
	scanf("%s", expression);
	x=strlen(expression);
	for (y=0;y<x;y++){
		numNodes++;
		input=push(expression[y], input, numNodes);
	}
	numNodes++;
	input=push(')', input, numNodes);
	numNodes++;
	input=push('\0', input, numNodes);
	infixtopostfix(input);
	getch();
}



Is This A Good Question/Topic? 0
  • +

Replies To: what is this kind of error?

#2 jwwicks  Icon User is offline

  • D.I.C Head
  • member icon

Reputation: 24
  • View blog
  • Posts: 162
  • Joined: 31-July 08

Re: what is this kind of error?

Posted 10 August 2008 - 03:32 AM

Hello qaz,

View Postqaz1134, on 10 Aug, 2008 - 02:53 AM, said:

hello guys i really need your help on this please help me!!!

here is my code

176 - 179 error structure required on left side of - or-* ?????? what is it???
	do{
		s.pop();
		output.pop();
		stack.pop();
		invalid.pop();
	}while((!(output==NULL))&&(!(stack==NULL))&&(!(s==NULL))&&(!(invalid==NULL)));



s, output, stack and invalid are pointers to structs. my_struct doesn't have a member called pop.

In all other cases the code had to do something like the following...

stack=pop(stack, stackNumNodes);



Try changing the above calls appropriately...

JW
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1