2014-11-23 53 views
0

我正試圖用這些3 typedef struct(人員,統計數據和車輛)創建一個單獨鏈接列表。創建BlockType結構的單向鏈表

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


typedef struct{ 
    char name[22]; 
    char city[10]; 
    int yearBorn; 
} person; 


typedef struct{ 
    int height[8]; 
    double weight[18]; 
    } Stats; 

typedef struct{ 
char car[16]; 
int horsepower[20]; 
} vehicle; 


typedef struct node { 
    person *p; 
    Stats *stat; 
    vehicle *hp; 
    struct node *next; 
}NODE; 

typedef struct { 
    NODE *head, *tail; 
}SLL; 


int main(){ 
void insert(SLL *list, person p, vehicle hp, Stats stat){ 


a = (NODE *)malloc(sizeof(p)); 
b = (NODE *)malloc(sizeof(hp)); 
c = (NODE *)malloc(sizeof(stat)); 

if(list->head == NULL){ 
return NULL; 
} 
list -> head -> next = a; 
list -> head -> next-> next = b; 
list -> head -> next-> next -> next = c; 
list -> tail = c; 


} 




return 0; 
} 

我不斷收到錯誤的A,B,&Ç說錯誤:「A」未聲明(先在這個函數中使用)。 我只是想知道如果我正在做這個正確的,這個錯誤意味着什麼。 我真的很感謝任何有關我的代碼的見解。謝謝。

+0

在使用它之前,需要聲明變量。這裏a,b,c沒有被聲明,而是直接使用它。 – 2014-11-23 04:08:19

+0

我該如何聲明它?一個無符號的字符? – 2014-11-23 04:17:49

+0

不,你沒有做到這一點。如果你是你不會從編譯器得到錯誤消息。錯誤消息意味着它說的是什麼。你的代碼的問題是'int main()'後面沒有一個正確或有意義的行。在嘗試重寫它之前,你需要花費幾個小時來刷新函數,變量和類型的基本概念。 – 2014-11-23 04:21:48

回答

0

的問題是在這裏

int main(){ 
    void insert(SLL *list, person p, vehicle hp, Stats stat){ 


    a = (NODE *)malloc(sizeof(p)); 
    b = (NODE *)malloc(sizeof(hp)); 
    c = (NODE *)malloc(sizeof(stat)); 

     if(list->head == NULL){ 
     return NULL; 
     } 
    list -> head -> next = a; 
    list -> head -> next-> next = b; 
    list -> head -> next-> next -> next = c; 
    list -> tail = c; 
    } 

return 0; 
} 

你如何定義等功能裏面的函數嗎?!

+0

我修復了它,但仍然無法正常工作 – 2014-11-23 04:13:53