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 に答える