2017-04-17 196 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 
    } 

} 
相关问题