用栈进制转换 输出乱码
#define _CRT_SECURE_NO_WARNINGS 1
#include<stdio.h>
#include<stdlib.h>
#include<assert.h>
#include<string.h>
#define MAXSIZE 2000
#define OVERFLOW -2
#define ERROR 0
#define OK 1
#define Status int
typedef int SELemType;
typedef struct
{
SELemType* base;
SELemType* top;
int stacksize;
}SqStake;
Status InitStack(SqStake* S)
{
S->base = (SELemType*)malloc(MAXSIZE * sizeof(SELemType));
if (!S->base)exit(OVERFLOW);
S->top = S->base;
S->stacksize = MAXSIZE;
return OK;
}
Status Push(SqStake* S, SELemType e) {
if (S->top - S->base == S->stacksize)
return ERROR;
*S->top++ = e;
return OK;
}
Status Pop(SqStake* S, SELemType* e) {
if (S->base == S->top)
return ERROR;
--S->top;
e = *S->top;
return OK;
}
int StackEmpty(SqStake S)
{
if (S.top ==S.base)
{
return 0;
}
else
{
return 1;
};
}
void conversion()
{
SqStake S;
SELemType h;
InitStack(&S);
printf("请输入非负的数:\n");
scanf("%d", &h);
while (h)
{
Push(&S, h % 8);
h = h / 8;
}
SELemType e;
while (StackEmpty(S))
{
Pop(&S, &e);
printf("%d", e);
}
}
void main()
{
conversion();
system("pause");
}