中易网

C语言error C2223: left of '->next' must point to struct/union

答案:2  悬赏:0  
解决时间 2021-04-28 12:39
  • 提问者网友:美人如花
  • 2021-04-27 19:28
#include
#include
#define MAXSIZE 100
#define OK 1
#define NULL 0
#define OVERFLOW -2

typedef struct
{
int data;
struct Lnode *next;
int Length;
}Lnode,*Linklist;
int main()
{
void scanf1(Linklist *L);
void display(Linklist *L);
Linklist *La;
scanf1(&La);
display(&La);
}
void scanf1(Linklist *L)
{
int node;
Linklist p;
L=(Linklist*)malloc(sizeof(Lnode));
L->next=NULL;
printf("输入第一个元素的值\n");
scanf("%d",&node);
while(node!=0)
{
p=(Linklist*)malloc(sizeof(Lnode));
p->data=node;
p->next=L->next;
L->next=p;
printf("输入元素,以0终止\n");
scanf("%d",&node);
}
}
void display(Linklist *L)
{
Linklist *p;
p=L->next;
while(p)
{
printf("%d\n",*p);
p=p->next;
}
}
H:\单链.c(24) : error C2082: redefinition of formal parameter 'L'
H:\单链.c(28) : error C2223: left of '->next' must point to struct/union
H:\单链.c(33) : warning C4047: '=' : 'struct Lnode *' differs in levels of indirection from 'struct Lnode ** '
H:\单链.c(35) : error C2223: left of '->next' must point to struct/union
H:\单链.c(36) : error C2223: left of '->next' must point to struct/union
H:\单链.c(44) : error C2223: left of '->next' must point to struct/union
H:\单链.c(48) : error C2223: left of '->next' must point to struct/union
最佳答案
  • 二级知识专家网友:随心随缘不随便
  • 2021-04-27 20:04
p要定义成LinkList类型
全部回答
  • 1楼网友:我们只是兮以城空
  • 2021-04-27 21:18
你的定义有问题,应该改为: typedef struct node* linkedlist; typedef struct node {   int data;  struct node *next; }; printf("%s ",p->data);改为printf("%d ",p->data); 完整代码; #include # include  # include  typedef struct node* linkedlist;  typedef struct node {   int data;  struct node *next; }; int main(void) {     int n=0;      linkedlist p,k;     k=(linkedlist)malloc(sizeof(struct node));     k->next=null;     while(n<5)     {             p=(linkedlist)malloc(sizeof(struct node));         p->data=2*n+1;         p->next=k->next;         k->next=p;         n++;         printf("%d ",p->data);     }     k->data=n;     return 0; }
我要举报
如以上回答内容为低俗、色情、不良、暴力、侵权、涉及违法等信息,可以点下面链接进行举报!
点此我要举报以上问答信息!
大家都在看
推荐信息