哪位高手帮我改改这个程序?编译时有一个错误。我用的是C++环境

来源:百度知道 编辑:UC知道 时间:2024/06/14 14:04:29
#include<stdio.h>
#define max 10
typedef struct
{char stack[max];
int top;
}qstype;
void initiateqs(qstype *s)
{s->top=-1;
}
int push(qstype *s,int x)
{if (s->top>=max-1)
return(0);
else{s->top++;
s->stack[s->top]=x;
return(1);}}
void main()
{int ch,sign;
qstype *s;
initiateqs(s);
printf(“>”);
scanf(“%d”,&ch);
while(ch!=-1)
if ((sign=push(s,ch))==0)
{printf(“overflow\n”);
break;}
else
scanf(“%d”,&ch);
while (s->top!=-1)
{s->top--;
printf(“stack=%d\n”,s->stack[s->top+1]);}
printf(“\n”);}
能帮我写出正确的程序吗?谢谢

你的指针要初始化后,再使用
qstype *s=(qstype*)malloc(sizeof(qstype));
initiateqs(s);
不初始化的话,程序很可能会崩溃!
要记得free掉!

双引号都错了! 我给你改了.
那个是警告不是错误
#include<stdio.h>
#define max 10
typedef struct
{
char stack[max];
int top;
}qstype;
void initiateqs(qstype *s)
{
s->top=-1;
}
int push(qstype *s,int x)
{
if (s->top>=max-1)
return(0);
else
{
s->top++;
s->stack[s->top]=x;
return(1);
}
}
void main()
{
int ch,sign;
qstype *s;
initiateqs(s);
printf(">");
scanf("%d",&ch);
while(ch!=-1)
{
if ((sign=push(s,ch))==0)
{
printf("overflow\n");
break;
}
else
scanf("%d",&ch);
}
while (s->top!=-1)
{
s->top--;
printf("stack=%d\n",s->stack[s->to