嗨,我正在尝试将文件中的变量读取到 int 数组中,以便可以将它们存储在 Struct 数组中。数字正确存储到 curLinks 数组中,但是当我尝试将 curLinks 数组传递到 curNodes.nodes 时,它不起作用,当我尝试将其打印出来(测试)时,它会打印出垃圾数字。任何帮助都会很棒。
struct nodeInfo* getTopology(FILE *file){
int totLinks=0;
fscanf(file, "%d", &nodeCount);
struct nodeInfo netTopo[nodeCount];
// How many links does node have
for (int id=0; id<nodeCount; id++){
struct nodeInfo curNode;
curNode.n=id;
fscanf(file, "%d", &totLinks);
int curLinks[totLinks];
for(int i=0; i<totLinks; i++){
int digit=0;
fscanf(file, "%d", &digit);
curLinks[i] = digit;
}
curNode.nodes = curLinks;
netTopo[id] = curNode;
}
for (int id=0; id<nodeCount; id++){
for (int j=0; j<3; j++){
printf("%d ", netTopo[id].nodes[j]);
}
}
return netTopo;
}