十进制转换八进制代码c语言,利用栈将十进制转换为八进制(C语言)
下面是我的代码,在C 上的报错很无语。。。高手解释下
#include
#include
#define STACK_INIT_SIZE 100;
#define STACKINCREMENT 10;
typede
下面是我的代码,在C 上的报错很无语。。。高手解释下
#include
#include
#define STACK_INIT_SIZE 100;
#define STACKINCREMENT 10;
typedef struct {
int *base;
int *top;
int stacksize;
}stack;
void initstack(stack *S){
S->base=(int *)malloc(STACK_INIT_SIZE*(int));
if(!S->base){
printf(“error”);
}
else{
S->base=S->top;
S->stacksize=STACK_INIT_SIZE;
}
}
void Push(stack *S,int e){
if(S->top-S->base>=S->stacksize){
S->base=(int *)realloc( S->base,(S->stacksize STACKINCREMENT)*sizeof(int));
S->top=S->base S->stacksize;
S->stacksize =STACKINCREMENT;
}
*S->top =e;
}
void Pop(stack *S,int *e){
if(S->base==S->top){
exit(1);
}
*e=*S->top;
S->top —;
}
void conversion(stack *S){
long int N;int e;
printf(“输入一个十进制数:”);
scanf(“%ld”,&N);
while(N){
Push(S,N%8);
N=N/8;
}
while(S->top!=S->base){
Pop(S,&e);
printf(“%d”,e);
}
}
void main(){
stack S;int i,e;
initstack(&S);
conversion(&S);
}
在线等候
展开
全部
还没有评论,来说两句吧...