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;
}
爲什麼你在那個循環中有一個struct re-declaration? –