用堆栈进行数制转化时出错,但如何检验也发现不了错误

来源:百度知道 编辑:UC知道 时间:2024/07/07 18:55:36
原程序是:
#define max 100
int stack[max],top=0;
int in_stack(int x)
{ if(top==max) return(0);
stack[top]=x;
top++;
}
int out_stack
{ if(top==0) return(-1);
top--;
return(stack[top]);
}
void main()
{ int x=567,y;
y=x;
while(x>0)
{ push(x%8);
x=x/8;
}
printf("\n %d=",y);
x=pop();
while(x!=-1)
{ printf("%d ",x);
x=pop();
}
}
但运行后总说
Warning 7:Function should return a value
Error 9: Declaration syntax error
请问哪里出错了?

int in_stack(int x)
{
if(top==max) return(0);
stack[top]=x;
top++;
}

这个函数在top!=max的情况下没有返回值导致的警告。

你双击一下,没有指定到哪一行吗?

#define max 100
int stack[max],top=0;
int in_stack(int x)
{
if(top==max)
return(0);
stack[top]=x;
top++;
return 1; //加一个返回值,你自己改
}
int out_stack(int top) //这里少一个参数列表
{
if(top==0)
return(-1);
top--;
return(stack[top]);
}
void main()
{
int x=567,y;
y=x;
while(x>0)
{
push(x%8);
x=x/8;
}
printf("\n %d=",y);
x=pop();
while(x!=-1)
{
printf("%d ",x);
x=pop();
}
}