weixin_45490561 2019-11-28 15:21 采纳率: 0%
浏览 284
已采纳

请问大神们这个代码运行后没有结果直接结束是为什么?

#include
#define max 100
typedef struct saqstack
{
int elem[max];
int top;
}saqstack;
int push(saqstack *s,int a)
{
if(s->top==max-1)
return 0;
else
{
s->top=s->top+1;
s->elem[s->top]=a;
return 1;}
}
int cs(saqstack *s)
{
s->top=-1;
}
int pop(saqstack *s,int *x)
{
if(s->top==-1)
return 0;
else
{
*x=s->elem[s->top];
s->top=s->top-1;
return 1;}

}
int print(saqstack *s)
{
printf("%d",s->elem[s->top]);
return 0;
}
int main()
{
saqstack *s;
int *x;
cs(s);
printf("pelase input the number;");
int a;
scanf("%d",&a);
push(s,a);
print(s);
push(s,1);
print(s);
pop(s,x);
print(s);
return 0;
}图片说明

  • 写回答

1条回答 默认 最新

  • qtchen_1988 2019-11-28 15:29
    关注
    saqstack *s;
    int *x;
    cs(s);
    
    int cs(saqstack *s)
    {
    s->top=-1;
    }
    你的指针没分配空间就直接用了,其他的也是
    
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?