Hi all. I'm new to this place, but I am really stuck and I figure maybe this is the place to go. The following peice of code is EXACTLY what my professor gave the class, and is the only demonstration of stacks he gave us. But, when you try to push items onto the stack, I get an error message! I don't even think the single bit of code he gave us is correct! when i compile (we have to compile under gcc) i get the following error message:
incompatible type for argument 1 of `push'
This is my code:
Code:
#include <stdio.h>
#define MAXSTACK 20
struct arraystack {
int items[MAXSTACK];
char quality[MAXSTACK];
int top;
};
void push( struct arraystack *produce, int x, char q );
void pop( struct arraystack *produce ,int *xx, char *qq);
int main( )
{
struct arraystack factory ;
factory.top = -1;
push( factory, 4, 'd'); //This is where the error comes in
return 0;
}
void push( struct arraystack *produce, int x, char q )
{
if ( produce->top >= MAXSTACK - 1 )
{
printf( "\n% Stack is full.\n");
}
else {
produce -> top = produce -> top + 1;
produce -> items[ produce -> top ] = x;
produce -> quality[ produce -> top ] = q;
}
}
void pop( struct arraystack *produce ,int *xx, char *qq)
{
int x = 0;
if ( produce->top < 0 )
{
printf("\nStack is empty");
}
else {
*xx = produce -> items[ produce ->top ];
*qq = produce -> quality[ produce ->top ];
produce -> top = produce -> top - 1;
}
}
what gives????