简单问题,十进制转八进制,用链栈做的找不出错误在哪,还望大神指点
#include "stdio.h"#include "stdlib.h"
#define OK 1
#define NO 0
typedef int Status;
typedef struct Stack
{
int value;
struct Stack *next;
}Stack;
int main()
{
Status InitStack(Stack*);
Status get_o(Stack*,int);
Status Pop(Stack*);
Stack *s;
s=(Stack*)malloc(sizeof(Stack));
int n;
if(!InitStack(s))
{
printf("haven't memory!\n");
return 0;
}
printf("please enter a number:\n");
scanf("%d",&n);
if(!get_o(s,n))
{
printf("can't save!\n");
return 0;
}
//while(s!=NULL)
Pop(s);
return 0;
}
Status InitStack(Stack *s)
{
if(!s)
{
printf("initfail!\n");
return NO;
}
s=NULL;
return OK;
}
Status get_o(Stack *s,int n)
{
Status Push(Stack*,int);
do
{
Push(s,n%8);
}while(n=n/8);
return OK;
}
Status Push(Stack *s,int a)
{
Stack *s1;
s1=(Stack*)malloc(sizeof(Stack));
s1->value=a;
s1->next=s;
s=s1;
return OK;
}
Status Pop(Stack *s)
{
Stack *s2=s;
printf("%d ",s->value);
s=s->next;
free(s2);
return OK;
}
[此贴子已经被作者于2019-7-6 07:36编辑过]