链栈 进行进制转换时碰到 隐藏的错误
程序能运行起来,但是老是报错.....
#include <stdio.h>
#include <malloc.h>
#define size 50
typedef struct Node
{
int elem[size];
int top;
}Stack;
//入栈
int push(Stack *L,int input)
{
if(L->top==size-1)
return 0;
L->top++;
L->elem[L->top]=input;
return 1;
}
//判空
int IsEmpty(Stack *s)
{
if(s->top==-1)
return 0;
else
return 1;
}
//出栈
int pop(Stack *s,int *del)
{
if(s->top==-1)
return 0;
*del=s->elem[s->top];
s->top--;
return 1;
}
//将任意正十进制数N,转换为二进制数输出
void Conver(int N)
{ //S为顺序栈或链栈
Stack S;
int x;
//InitStack(&S);
while(N>0)
//将模2余数入栈
{ x=N%8;
push(&S, x);
N=N/8;
}
//非空继续
while(!IsEmpty(&S))
{
//出栈,输出
pop(&S,&x); printf("%d",&x);
}
}
void main()
{
Conver(1348);
}