C - initialize array of structs

前端 未结 4 707
情歌与酒
情歌与酒 2020-12-14 18:49

I am having a problem initializing an array of structs. I\'m not sure if I am doing it right because I get \"initialization from incompatible pointer type\" & \"assignme

4条回答
  •  不知归路
    2020-12-14 19:54

    student* students = malloc(sizeof(student)*numStudents);
    int x;
    for(x = 0; x < numStudents; x++)
    {
        student newStudent = {"john", "smith", 1, 12, 1983}; // string copy are wrong still
        students[x] = newStudent;
    }
    

提交回复
热议问题