0
#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); // 非法使用指针???怎么会这样?

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

4

1 回答 1

2

您的 typedef 错误,应该是:

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

而且你在一些电话中缺少逗号scanf

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

于 2013-03-15T14:23:43.843 回答