基本上,我有一个这样定义的结构:
struct D_Array
{
int Capacity;
int Cur_Size;
struct Student* List;
};
现在,在创建结构之后;
struct D_Array* T_Array;
if (T_Array = malloc(sizeof(struct D_Array)) == NULL)
{
printf("There has been a problem with memory allocation. Exiting the program.");
exit (21);
}
我在此结构内创建学生列表时遇到问题。我需要该列表是一个指针数组,因为我应该制作某种ADT程序,所以我试图使它像这样:
T_Array->Capacity = 10;
T_Array->Cur_Size = 0;
T_Array->List[10]= (struct Student*) malloc(sizeof (struct Student*));
不管如何尝试更改它,我都会遇到相同的错误:从“结构学生*”类型分配给“结构学生”类型时,类型不兼容|
我正在尝试创建一个数组,我将能够执行类似的操作;
T_Array->List[1]=Student_Pointer;
谢谢!
将数组的类型更改为struct Student **,它将是指针数组:
struct student *->指向学生的指针。struct student **->指向学生的指针(您需要的指针)。
struct D_Array
{
int Capacity;
int Cur_Size;
struct Student** List;
}
和分配:
T_Array->List = malloc (sizeof (struct Student*) * lengthofarray);
然后:
T_Array->List[1]=Student_Pointer;
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句