gpt4 book ai didi

c - 为什么这不起作用?[链接列表]

转载 作者:行者123 更新时间:2023-11-30 14:20:28 25 4
gpt4 key购买 nike

#include<conio.h>
#include<stdio.h>
#include<alloc.h>
typedef struct node
{
int data;
struct node *n_next,*next,*p_pre,*pre;
};

int main()
{
node *head,*p,*q,*r,*s;
head=(struct node*) malloc(sizeof(struct node));
p=head;
q=(struct node*) malloc(sizeof(struct node));
r=(struct node*) malloc(sizeof(struct node));
s=(struct node*) malloc(sizeof(struct node));

printf(" \nEnter the data of the node ");
scanf("%d",&p->data);

printf("\nEnter the data for second node ");
scanf("%d "&q->data);

printf("\nEnter the data for third node ");
scanf("%d "&r->data);

printf("\nEnter the data for fourth node ");
scanf("%d ",&s->data);
getch();
return(0);
}

编译后,代码预计会获取4个数据值并将它们存储在相关节点的数据字段中,但它说..

scanf("%d",&p->data); // Illegal use of pointer???? How is that so?

代码的哪一部分被破坏并且应该修复?

最佳答案

你的typedef是错误的,应该是:

typedef struct node
{
int data;
struct node *n_next,*next,*p_pre,*pre;
} node; // <---

并且您在 scanf 的某些调用中缺少逗号:

scanf("%d"&q->data);

关于c - 为什么这不起作用?[链接列表],我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15434719/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com