#include<stdio.h>
#include<malloc.h>
#include<stdlib.h>
#define MAXSIZE 100
#define OVERFLOW -1
#define OK 1
#define ERROR -1
void exit(int value);
typedef char Status;
typedef int SElemType;
typedef struct
{
SElemType *base;
SElemType *TOP;
int stacksize;
}SqStack;
//初始化
Status InitStack(SqStack *S)
{
S->base=(SElemType *)malloc(sizeof(SElemType *));
if(!S->base) exit(OVERFLOW);
S->TOP=S->base;
S->stacksize=MAXSIZE;
return OK;
}
//压栈
Status push(SqStack *S,SElemType e)
{
if(S->TOP-S->base==S->stacksize) return ERROR;
else
e=*S->TOP;
S->TOP=S->TOP+1;
return OK;
}
//出栈
Status pop(SqStack *S,SElemType e)
{
if (S->TOP== S->base)
{
return ERROR;
}
else
{
printf("%d\n",e);
S->TOP= S->TOP-1;
e=*S->TOP-1;
//printf("%d\n",e);
return OK;
}
}
//判空
Status StackEmpty(SqStack *S){
if (S->base == S->TOP)
{
return 1;
}
else{
return 0;
}
}
//进制转化
void conversion(SqStack *S,int N)
{
int a=1;
SElemType e;
//InitStack(S);
while(N)
{
a=N%8;
// printf("%d\n",a);
push(S,a);
N=N/8;
}
printf("转化的八进制是:");
while(!StackEmpty(S))
{
pop(S,e);
printf("%d",e);
}
}
main()
{
int N;
SqStack S;
InitStack(&S);
scanf("%d",&N);
conversion(&S,N);
return 0;
}
运行结果一直是1919不知道为什么