2013-10-12 51 views
0

嗨我有一個函數下面,每次我編譯它給我的錯誤:「錯誤:分配給'struct nodeInfo'從不兼容的類型'struct nodeInfo'」,我不知道如何修正它,因爲我宣佈了一個相同類型的數組。歡迎任何幫助。C結構數組類型在C

編輯:netTopo [id] = curNode;線路引起了問題。

struct nodeInfo *getTopology(FILE * file) 
{ 
    int totLinks = 0, digit = 0; 

    fscanf(file, "%d", &nodeCount); 
    struct nodeInfo netTopo[nodeCount]; 

    // How many links does node have 
    for (int id = 0; id < nodeCount; id++) 
    { 
     struct nodeInfo 
     { 
      int n; 
      int *links; 
     } curNode; 

     curNode.n = id; 
     fscanf(file, "%d", &totLinks); 
     for (int i = 0; i < totLinks; i++) 
     { 
      curNode.links[totLinks]; 
      fscanf(file, "%d", &digit); 
      curNode.links[i] = digit; 
     } 
     netTopo[id] = curNode; 
    } 
    return netTopo; 
} 
+1

爲什麼你在那個循環中有一個struct re-declaration? –

回答

3

您已定義nodeInfo兩次。

而不是

struct nodeInfo { 
    int n; 
    int *links; 
} curNode; 

嘗試

struct nodeInfo curNode; 

你的第一個聲明沒有顯示,所以我只猜你打算他們是相同的。