#无法打印出栈数据
#
#include<stdio.h>
#include<malloc.h>
#include<stdlib.h>//realloc
#include<string.h>
#define Status int
#define OK 1
#define ERROR 0
#define OVERFLOW -2
#define STACK_INIT_SIZE 100
#define STACKINCREMENT //stackincrement
//自定义数据类型
typedef int SElemType;
typedef struct
{
SElemType *base;
SElemType *top;
int stacksize;
}SqStack;
//构造一个空栈
Status InitStack(SqStack *S)
{
S->base = (SElemType * )malloc(STACK_INIT_SIZE * sizeof(SElemType));
if( !S->base )exit(OVERFLOW);
S->top=S->base;
S->stacksize=STACK_INIT_SIZE;
return OK;
}
//入栈
Status Push(SqStack *S , SElemType e)
{
if((S->top - S->base) >= S->stacksize)
{
return ERROR;
}
/*{
S->base = (SElemType * )realloc(S->base,(S->stacksize+STACKINCREMENT)*sizeof (SElemType));
if (!S->base)exit(OVERFLOW);
S->top = S->base + S->stacksize;
S->stacksize+=STACKINCREMENT;
}*/
*S->top++=e;
return OK;
}
//出栈
Status Pop(SqStack* S, SElemType* e)
{
if(S->top==S->base)
{
return ERROR;
}
e = * --S->top;
return OK;
}
//判断是否为空栈
Status StackEmpty(SqStack S)
{
if(S.top==S.base)
return ERROR;
else
return OK;
}
//功能:将十进制数转换为八进制数
void conversion()
{
SqStack S;
SElemType N;
InitStack(&S);
printf("请输入非负的数:\n");
scanf("%d",&N);
while(N)
{
Push(&S,N%8);
N=N/8;
}
SElemType e;
while (StackEmpty(S))
{
//printf("text");
Pop(&S,e);
printf("%d",e);
}
}
int main()
{
printf("欢迎使用进制数转换程序!!\n") ;
conversion();
system("pause");
}
61 4 [Warning] assignment makes pointer from integer without a cast
In function 'conversion':
93 10 [Warning] passing argument 2 of 'Pop' makes pointer from integer without a cast
55 8 [Note] expected 'SElemType *' but argument is of type 'SElemType'