2017-04-17 15 views
-1

構造を宣言するのは間違いでしたか?私はこのエラーに基づいていくつかの他の同様の質問をチェックしようとしたが、解決策を見つけることができなかった。それを解決するためにあなたの助けが必要です。アドバンスで感謝します。C構造エラー:不完全な型へのポインタを参照解除する

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

struct Node{ 
int info; 
struct node *link; 
} ; 

void display(struct node *start); 

int main() 
{ 
struct node *start=NULL; 

int choice; 
int num; 

while(1) 
{ 
printf("\n1. Display \n9. Exit \n"); 

printf("\nEnter your choice\n\n\n"); 
scanf("%d",&choice); 

switch(choice) 
{ 
case 1: 
    display(start); 
    break; 

default: 
    printf("\nInvalid choice"); 

} 
} 
} 
void display(struct node *start) 
{ 
    struct node *p; 

    if(start==NULL) 
    { 
     printf("List Is Empty"); 
     return; 
    } 
    p=start; 
    while(p!=NULL) 
    { 
     printf("%d",p->info); // Getting Error in these 2 Lines 
     p=p->link;   // Getting Error in these 2 Lines 
    } 

} 
+7

を使用し '構造体Node'ではないため、構造体のノードとしてあなたのコード内で定義されたものは何もありません'struct node'と同じことです。 – aschepler

+0

@aschelperありがとう、私はそれを知らなかった。それは働いた。手伝ってくれてありがとう。あなたはそれらの違いを説明してくれる? – harsher

+0

違いは大文字Nです。冗談だ。 * C *は大文字と小文字を区別します。 –

答えて

0

struct nodeへのポインタを宣言しますが、その型は定義されていません。 Cは大文字小文字を区別します

ここでエラーが発生する理由は、コンパイラが実際にレイアウトを知る必要がある構造体へのポインタを逆参照しようとするまではないということです。

+0

ありがとうEveryone。 – harsher

0

大文字小文字の問題のように見えますが、struct Nodeがありますが、それ以外の場合は完全ではありません。struct node *です。

0

は、このStructノードを見て*と構造体のノード*を持っている:

最初のあなたは、構造体のノードに

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

    struct node ///<<< fix 
    { 
    int info; 
    struct node *link; 
} ; 

void display(struct node *start); 

int main() 
{ 
    struct node *start=NULL; 

    int choice; 
    int num; 

    while(1) 
    { 
     printf("\n1. Display \n9. Exit \n"); 

     printf("\nEnter your choice\n\n\n"); 
     scanf("%d",&choice); 

     switch(choice) 
     { 
     case 1: 
      display(start); 
      break; 

     default: 
      printf("\nInvalid choice"); 

     } 
    } 
    } 
    void display(struct node *start) 
    { 
    struct node *p; 

    if(start==NULL) 
    { 
     printf("List Is Empty"); 
     return; 
    } 
    p=start; 
    while(p!=NULL) 
    { 
     printf("%d",p->info); // Getting Error in these 2 Lines 

    /// struct node and struct Node are diffrent things 

     p=p->link;   // Getting Error in these 2 Lines 
    } 

} 
関連する問題