栈的应用 求大神帮助,为什么求不出长度来
#include "stdio.h"#include "malloc.h"
#define stack_size 10
#define error
#define ok
typedef char elemtype;
typedef struct stack
{
elemtype elem[stack_size];
int top;
int length;
}sqstack;
void emptystack(sqstack *s)/*置空栈*/
{
s->top=-1;
}
int leng(sqstack *s)
{
return (s->length);
}
int push(sqstack *s,elemtype e)/*进栈*/
{
if(s->top>=stack_size-1)
return error;
else
{
s->top++;
s->elem[s->top]=e;
return ok;
}
}
/*int pop(sqstack *s,elemtype *e)
{
if(s->top<0)
return error;
else
{
*e=s->elem[s->top];
s->top--;
return ok;
}
}*/
int main()
{
sqstack s;
emptystack(&s);
push(&s,'a');
push(&s,'b');
printf("%d",leng(&s));
getch();
}