读书人

进制转换不能通过 帮忙看一下解决办法

发布时间: 2012-02-26 20:19:44 作者: rapoo

进制转换不能通过 帮忙看一下
#include <stdio.h>
#define Maxsize 100

typedef struct{
int date[Maxsize];
int top;
}SqStack;
void InitStack(SqStack *st)
{
st-> top=-1;
}
int StackEmpty(SqStack *st)
{
return(st-> top==-1);
}

int Push(SqStack *st,int x)
{
if(st-> top=Maxsize-1)
return 0;
st-> top++;
st-> date[st-> top]=x;
return 1;
}
int Pop(SqStack *st,int *x)
{
if(st-> top==-1)
return 0;
st-> date[st-> top]=*x;
st-> top--;
return 1;
}

void conversion(void)
{
int n,x;
SqStack *s;
InitStack(s);
scanf( "%d ",&n);
while(n){
Push(s,n%8);
n=n/8;
}
while(!StackEmpty(s))
{
Pop(s,&x);
printf( "%d ",x);
}
}

int main(void)
{
conversion();
return 0;
}



[解决办法]
#include <stdio.h>
//这
#include <stdlib.h>
#define Maxsize 100

typedef struct{
//这,虽然你一直这样写,但应该是data
int date[Maxsize];
int top;
}SqStack;
void InitStack(SqStack *st)
{
st-> top=-1;
}
int StackEmpty(SqStack *st)
{
return(st-> top==-1);
}

int Push(SqStack *st,int x)
{//这
if(Maxsize-1==st-> top)
return 0;
st-> top++;
st-> date[st-> top]=x;
return 1;
}
int Pop(SqStack *st,int *x)
{
if(st-> top==-1)
return 0;
//这
*x=st-> date[st-> top];
st-> top--;
return 1;
}

void conversion(void)
{
int n,x;
//这
SqStack *s=(SqStack*)malloc(sizeof(SqStack));
InitStack(s);
scanf( "%d ",&n);

while(n){
Push(s,n%8);
n=n/8;
}
while(!StackEmpty(s))
{
Pop(s,&x);
printf( "%d ",x);
}
}

int main(void)
{
conversion();
return 0;
}

读书人网 >软件架构设计

热点推荐