标题:[讨论]斑竹看过来--数值转化
取消只看楼主
xiaofkg
Rank: 1
等 级:新手上路
威 望:1
帖 子:77
专家分:0
注 册:2007-9-17
 问题点数:0 回复次数:0 
[讨论]斑竹看过来--数值转化
这个程序是把十进制
转化为八进制,编译成功,可是结果确是错误的.请高手看看,提出建议


#include <stdio.h>
#include <stdlib.h>
#define OK 1
#define ERROR 0
#define OVERFLOW -2
#define STACK_INIT_SIZE 100
#define STACKINCREMENT 100
typedef struct
{int *base;
int *top;
int stacksize;
}sqstack;
push(sqstack *s,int e)
{if(s->top-s->base>=s->stacksize)
{s->base=realloc(s->base,(s->stacksize+STACKINCREMENT)*sizeof(int));
if(!s->base)exit(OVERFLOW);
s->top=s->base+s->stacksize;
s->stacksize+=STACKINCREMENT;
}
*s->top++=e;
return OK;
}
pop(sqstack *s,int *e)
{if(s->top==s->base) return ERROR;
e=*--s->top;
return OK;
}
initstack(sqstack *s)
{s->base=(int *)malloc(STACK_INIT_SIZE*sizeof(int));
if(!s->base) exit(OVERFLOW);
s->top=s->base;
s->stacksize=STACKINCREMENT;
return OK;
}
emptystack(sqstack *s)
{if(s->top==s->base)
return OK;
return ERROR;
}

void conversion()
{sqstack s;
int n,e;
initstack(&s);
scanf("%d",&n);
while(n)
{push(&s,n%8);
n=n/8;
}
while(!emptystack(&s))
{pop(&s,&e);
printf("%d",e);
}
}
int main()
{ conversion();
getch();
}
搜索更多相关主题的帖子: 数值 斑竹 
2007-10-22 10:20



参与讨论请移步原网站贴子:https://bbs.bccn.net/thread-179715-1-1.html




关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.267008 second(s), 8 queries.
Copyright©2004-2025, BCCN.NET, All Rights Reserved