#include<stdio.h>
//#include
#include<malloc.h>
#include<stdlib.h>
#define MAXSIZE 100
#define OVERFLOW -1
#define OK 1
#define ERROR -1
//using namespace std;
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;
e=*S->TOP++;
return OK;
}
//出栈
Status pop(SqStack *S,SElemType e){
if (S->TOP== S->base)
{
return ERROR;
}
e = *S->TOP;
S->TOP= S->TOP - 1;
return OK;
}
//判空
Status StackEmpty(SqStack *S){
if (S->base == S->TOP)
{
return 1;
}else{
return 0;
}
}
//进制转化
void conversion(SqStack *S,int N)
{
int a;
SElemType e;
//InitStack(S);
while(N)
{
a=N%8;
push(S,a);
N=N/8;
}
printf("转化的八进制是:");
while(!StackEmpty(S))
{
pop(S,a);
printf("%d",e);
}
}
main()
{
int N;
SqStack S;
InitStack(&S);
scanf("%d",N);
conversion(&S,N);
}
运行不了
主函数需要修改,望采纳!
int main()
{
int N;
SqStack S;
InitStack(&S);
scanf("%d",N);
conversion(&S,N);
return 0;
}