2017-04-17 71 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謝謝,我不知道,它工作。感謝幫助。 Cud你解釋他們之間的區別? – harsher

+0

區別是大寫N :)。開玩笑。 * C *區分大小寫。 –

回答

0

您聲明指針struct node,但沒有定義的類型。 C區分大小寫。

你得到錯誤的原因是你直到你試圖取消引用一個指向struct的指針時,編譯器實際上需要知道這個佈局。

+0

謝謝大家。 – harsher

0

看起來像一個字符大小寫的問題:你有struct Node,但隨後struct node *,不能是任何完整的,不是在所有。

0

看一看這個結構節點*和結構*節點:

有在你的代碼定義爲結構節點,因爲你首先使用結構節點

#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 
    } 

} 
相關問題