这段代码错在哪里呢

vecshid 2007-12-19 04:52:52
#include <stdio.h>
#include <stdlib.h>

typedef struct node
{
int data;
struct node *next;
}sLink;

void InitList(sLink **L)
{
*L = (sLink*)malloc(sizeof(sLink));
if (*L == NULL)
{
exit(0);
}
*L->next = NULL; //这句话出错
}

void main()
{
sLink *a;
InitList(&a);
}

怎么回事呢? 错误说:error C2223: left of '->next' must point to struct/union,*L不就是一个struct吗?
...全文
111 6 打赏 收藏 转发到动态 举报
AI 作业
写回复
用AI写文章
6 条回复
切换为时间正序
请发表友善的回复…
发表回复
silencezhujianhua 2007-12-19
  • 打赏
  • 举报
回复
*L-> next = NULL; //这句话出错
那个->的优先级别高于*
所以要改一下
(*L)-> next = NULL; //这句话出错
vecshid 2007-12-19
  • 打赏
  • 举报
回复
Treazy

等 级: 发表于:2007-12-19 17:00:43
1楼 得分:0
*L-> next = NULL;
改成
(*L)-> next = NULL;

*L才是个struct,所以要放一起!不然被编译器认为*(L-> next)
================================
非常感谢
chlaws 2007-12-19
  • 打赏
  • 举报
回复

#include <stdio.h>
#include <stdlib.h>

typedef struct node
{
int data;
struct node *next;
}sLink;

void InitList(sLink *L)
{
L = (sLink *)malloc(sizeof(sLink));
if (L == NULL)
{
exit(0);
}
L-> next = NULL;
}

void main()
{
sLink *a;
InitList(a);
printf("ok~ ");
}



Treazy 2007-12-19
  • 打赏
  • 举报
回复
写错了一个地方

*L是个sLink *,所以要放一起!不然被编译器认为*(L->next)
ckt 2007-12-19
  • 打赏
  • 举报
回复
顶楼上
Treazy 2007-12-19
  • 打赏
  • 举报
回复
*L-> next = NULL;
改成
(*L)-> next = NULL;

*L才是个struct,所以要放一起!不然被编译器认为*(L->next)

70,020

社区成员

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

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