关于数据与结构链栈的问题(十进制转八进制)
以下是我写的代码,可是一直循环。求各位大神指点#include<stdio.h>#include<stdlib.h>
typedef struct StackNode
{
int data;
StackNode *next;
}StackNode,*LinkStack;
void InitStack(LinkStack S)
{
S=NULL;
}
void Push(LinkStack S,int N)
{
StackNode *q;
q=(StackNode*)malloc(sizeof(StackNode));
q->data=N%8;
q->next=S;
S=q;
}
void Pop(LinkStack S)
{
LinkStack q;
q=S;
printf("%d",S->data);
S=S->next;
free(q);
}
int main()
{
LinkStack S;
int N,e;
S=(LinkStack)malloc(sizeof(StackNode));
InitStack(S);
scanf("%d",&N);
while(N)
{
Push(S,N);
N=N/8;
}
while(S)
{
Pop(S);
}
}