gpt4 book ai didi

c - 如何访问结构数组中的变量

转载 作者:太空宇宙 更新时间:2023-11-04 07:20:50 25 4
gpt4 key购买 nike

在下面的 for 循环中,我尝试访问存储在另一个结构中的结构数组,但我继续收到一条错误消息。 “结构列表没有成员头。”

list* createList(int size)
{
list* graph = malloc(sizeof(list));
graph->size = size;
graph->array = malloc(size * sizeof(vertex));
int i;
for(i=0; i < size;i++){
graph->array[i].head = NULL;
return graph;
}
}

我尝试使用的结构如下。

struct vertex
{
struct vertex *head;
};
typedef struct vertex vertex;

struct list
{
int size;
struct list* array;
};
typedef struct list list;

最佳答案

你的 list 成员是 list 类型,而它应该是 vertex 类型。

关于c - 如何访问结构数组中的变量,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21739615/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com