回复 2楼 邓士林
#include<stdio.h>
#include<stdlib.h>
#define STACK_INIT_SIZE 100
#define STACK_INCREMENT 10
typedef struct
{
int *top;
int *base;
int stacksize;
}sqstack;
//栈结构体定义
sqstack * initstack(sqstack *a){
a->base=(int *)malloc(STACK_INIT_SIZE*sizeof(int));
// if(!a->base) exit(0);
a->top=a->base;
a->stacksize=STACK_INIT_SIZE;
return a;
} //栈的初始化操作
sqstack *push(sqstack *a,int x){
if(a->top-a->base==a->stacksize){
a->base=(int *)realloc(a->base,(a->stacksize+STACK_INCREMENT)*sizeof(int));
if(!a->base) exit(0);
a->top=a->base+a->stacksize;
a->stacksize+=STACK_INCREMENT;}
a->top++; *a->top=x;
return a;
}//元素的入栈操作
void pop(sqstack *a){
int e;
for(a->top;a->top!=a->base;a->top--)
{
e=*a->top;
printf("%d",*a->top);}
} //元素的出栈操作
void main()
{
sqstack s; int n;
这里如果改成sqstack *s 下面全部用s替换程序就运行不出来
initstack(&s);
printf("stack initial finshed!\n");
printf("请输入要转换成八进制的数\n");
scanf("%d",&n);
while(n){
push(&s,n%8);
n=n/8;
}
pop(&s);
}