链栈 求解!~在线等。。。。

metears 2010-10-08 04:14:11
为什么编译通过 运行不行???????


#include<stdio.h>
#include<stdlib.h>
typedef int ElemType;
typedef int Status;
typedef struct stacknode
{
ElemType data;
struct stacknode *next;
}stacknode;

typedef struct stacklink
{
stacknode *top;
ElemType stacklength;
}stacklink;
Status Initstack(stacklink *s)
{
s->top=(struct stacknode*)malloc(sizeof(struct stacknode));
if(!s->top)
return 0;
s->top->data=0;
s->top->next=NULL;
s->stacklength=0;
return 1;
}
int main(int argc, char *argv[])
{
stacklink *mystack;
if(Initstack(mystack))
printf("ok\n");
else
printf("error");
system("PAUSE");
return 0;
}

...全文
126 9 打赏 收藏 转发到动态 举报
AI 作业
写回复
用AI写文章
9 条回复
切换为时间正序
请发表友善的回复…
发表回复
metears 2010-10-09
  • 打赏
  • 举报
回复
[Quote=引用 7 楼 logiciel 的回复:]
改2行:

stacklink mystack; //stacklink *mystack;
if(Initstack(&mystack)) //if(Initstack(mystack))
[/Quote]
谢谢 改是改对了 能帮忙稍稍解释下嘛?
thegreatone 2010-10-08
  • 打赏
  • 举报
回复
楼上正解。
logiciel 2010-10-08
  • 打赏
  • 举报
回复
改2行:

stacklink mystack; //stacklink *mystack;
if(Initstack(&mystack)) //if(Initstack(mystack))
metears 2010-10-08
  • 打赏
  • 举报
回复
还是不行啊 求解啊
metears 2010-10-08
  • 打赏
  • 举报
回复
[Quote=引用 1 楼 csuxiaowu 的回复:]
gcc表示可以 输出OK
[/Quote]
gcc 可以?
我用的是Dev-C++ 运行的 不行啊
metears 2010-10-08
  • 打赏
  • 举报
回复
[Quote=引用 2 楼 hai040 的回复:]
mystack(s)没申请空间
[/Quote]
需要怎么该啊?
kyzy_yy_pm 2010-10-08
  • 打赏
  • 举报
回复
可以啊,输出ok
hai040 2010-10-08
  • 打赏
  • 举报
回复
mystack(s)没申请空间
Csuxiaowu 2010-10-08
  • 打赏
  • 举报
回复
gcc表示可以 输出OK

70,023

社区成员

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

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