0
typedef struct stnode {
    unsigned number;
    char * name;
    unsigned section;
    struct stnode * next;
} StudentNode; 

void buildStudentSections(StudentNode * sections[], StudentNode students[], size_t num_students) {

        if(!num_students) return ;
        StudentNode * aux=NULL;

        for(int i=0;i<num_students;i++){

            aux=sections[students[i].section];
            (**(sections+students[i].section)).next=*(students+i);


            }   

    }

当我尝试执行此代码时,出现此错误:

incompatible types when assigning to type ‘struct stnode *’ from type ‘StudentNode’

代码有什么问题,我已经尝试了很多东西,但没有奏效。我只想将下一个指向我正在分析的“学生”

4

3 回答 3

2

阅读编译器错误(您尚未执行此代码 - 它尚未编译...)

来自“StudentNode”类型的“struct stnode *”</p>

基本上,您正在尝试将结构分配给指针,这是行不通的。查看以下行:

(**(sections+students[i].section)).next=*(students+i);

问题在于取消引用.(students + 1)

于 2013-10-21T13:53:03.053 回答
1

问题是*(students+i)取消引用元素students+i。它应该是:

(**(sections+students[i].section)).next=students+i;
于 2013-10-21T13:54:19.150 回答
0

改变这个:

void buildStudentSections(StudentNode * sections[], StudentNode students[], size_t num_students) {

        if(!num_students) return ;
        StudentNode * aux=NULL;

        for(int i=0;i<num_students;i++){

            aux=sections[students[i].section];       // = *(x) you are dereferencing students+1
            (**(sections+students[i].section)).next=*(students+i);


            }   

    }

对此:

void buildStudentSections(StudentNode * sections[], StudentNode students[], size_t num_students) 
{

        if(!num_students) return ;
        StudentNode * aux=NULL;

        for(int i=0;i<num_students;i++)
        {

            aux=sections[students[i].section];      //removed '*`
            (**(sections+students[i].section)).next = (students+1); 


        }   

}
于 2013-10-21T14:26:51.297 回答