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? –