求高手解决这个问题啊 关于C的

晓飞趋势 2011-06-12 11:55:50
下面是我用C语言编写的程序 (这个程序主要是为了实现十进制转换成16进制)


#include<stdio.h>
#include<stdlib.h>
#include<math.h>
#define STACK_INIT_SIZE 100
#define STACKINCREMENT 10
typedef struct
{
int *base;
int *top;
int stacksize;
}SqStack;

SqStack InitStack(SqStack S)
{
S.top=(int *)realloc(S.base,(S.stacksize+STACKINCREMENT)*sizeof(int));
S.base=(int *)realloc(S.base,(S.stacksize+STACKINCREMENT)*sizeof(int));
if(!S.base)
exit(-1);
S.top=S.base;
S.stacksize=STACK_INIT_SIZE;
return S;

}

void Push(SqStack S,int e)
{
if(S.top-S.base>=S.stacksize)
{
S.base=(int *)realloc(S.base,(S.stacksize+STACKINCREMENT)*sizeof(int));
if(!S.base)
exit(-1);
S.top=S.base+S.stacksize;
S.stacksize+=STACKINCREMENT;
}
else
*(S.top)++=e;

}
int StackEmpty(SqStack S)
{
if(S.top==S.base)
return 0;
else
return 1;
}


int Pop(SqStack S,int e)
{
if(S.top==S.base)
{
printf("error!\n");
}
else
{
e=*--S.top;
}
return e;
}
void Conversion(SqStack S,int N,int e)
{
while(N){
Push(S,N%16);
N=N/16;
}

}
void print(SqStack S)
{
int e;
printf("转换后:\n");
while(!StackEmpty(S))
{
printf("%d",Pop(S,e));
}

}

int main()
{
int N;
int e;
SqStack S;
printf("请输入十进制数:");
scanf("%d",&N);
S=InitStack(S);
Conversion( S, N, e);
print(S);
}





可是老是出现这个错误
H:\数据结构作业\栈与对列\shuzhi.c(74) : warning C4700: local variable 'e' used without having been initialized
H:\数据结构作业\栈与对列\shuzhi.c(86) : warning C4700: local variable 'S' used without having been initialized
H:\数据结构作业\栈与对列\shuzhi.c(87) : warning C4700: local variable 'e' used without having been initialized




实在是不知道怎么修改了 希望高手帮个忙
...全文
54 4 打赏 收藏 转发到动态 举报
写回复
用AI写文章
4 条回复
切换为时间正序
请发表友善的回复…
发表回复
Vonvnie 2011-06-12
  • 打赏
  • 举报
回复
1楼+1
蓝染忽右介 2011-06-12
  • 打赏
  • 举报
回复
S,e 没初始化!!
sduxiaoxiang 2011-06-12
  • 打赏
  • 举报
回复

SqStack InitStack(int size)
{
S.top=(int *)malloc((size + STACKINCREMENT)*sizeof(int));
S.base=(int *)malloc((size + STACKINCREMENT)*sizeof(int));
if(!S.base)
exit(-1);
S.stacksize=STACK_INIT_SIZE+size;
return S;
}

增加新的构造函数

S=InitStack(50);

另外无析构函数,存在内存泄露
ryfdizuo 2011-06-12
  • 打赏
  • 举报
回复
这些变量没有初始化就直接使用。

69,369

社区成员

发帖
与我相关
我的任务
社区描述
C语言相关问题讨论
社区管理员
  • C语言
  • 花神庙码农
  • 架构师李肯
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧