I'm trying to write some stack implementation code here and I'm hung up on a few compiling errors/looking for some clarification on a few of the issues I'm seeing.
In particular I'm having difficults figuring out what the input should be in the main function for my functions to run. They expect pointers as inputs, how do I give them pointers?
My isEmpty() and my push() don't like my inputs. :(
Here is my code--
#include <stdio.h>
#include <conio.h>
#define MAX 100
typedef struct {
int * st; // array of the data on the stack
int size;
int T;
int x;
int a[];
} stack;
void push(stack *st, int item) {
printf("\nT value%d",st->T);
st->T++;
if (st->T >= st->size) {
printf("\nStack size limit reached, can't push.");
return;
}
st->T++;
printf("\nT value%d",st->T);
st->a[st->T]=item;
printf("\n array value at position T %d", st->a[st->T]);
}
int pop(stack *st) {
int item;
printf("\nT value%d", st->T);
item=st->a[st->T];
printf("\n item= %d", item);
st->T--;
printf("\nT value%d", st->T);
return(item);
}
int size(stack *st){
int size_of_stack=0;
size_of_stack = st->T + 1;
printf ("\n size of stack = %d", size_of_stack);
return size_of_stack;
}
int isEmpty(stack *st)
{
if(st->T == -1)
return(1);
else
return(0);
}
int top(stack *st, stack T){
int value= st->T;
return(value);
}
void print(stack *st){
int i;
if (isEmpty(*st)==1)
printf("\n Stack is empty! \n");
else {
for (i=st->T; i>= 0 ; i-- )
printf ("\n%d",st->a[i]);
}
}
int main(){
int st[MAX],item;
int T=-1;
int a[6]={10,20,30,40,50,60};
push(* st,2);
}
Here are the compile errors that I'm getting for this.
λ gcc a3.c
a3.c: In function 'print':
a3.c:60:6: error: incompatible type for argument 1 of 'isEmpty'
if (isEmpty(*st)==1)
^
a3.c:45:5: note: expected 'struct stack *' but argument is of type 'stack'
int isEmpty(stack *st)
^
a3.c: In function 'main':
a3.c:72:7: warning: passing argument 1 of 'push' makes pointer from integer without a cast
push(* st,2);
^
a3.c:14:6: note: expected 'struct stack *' but argument is of type 'int'
void push(stack *st, int item) {